:root {
  --navy-950: #0f1a2d;
  --navy-900: #13213a;
  --blue-600: #2f80ed;
  --blue-100: #eaf3ff;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --border: #dbe3ef;
  --border-strong: #b9c7da;
  --text: #172033;
  --muted: #5f6f85;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 18px 45px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overflow-x: hidden;
}

body,
button,
input {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  cursor: pointer;
}

:is(a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"])):focus {
  outline: 3px solid var(--blue-600);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(47, 128, 237, 0.18);
}

:is(a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"])):focus:not(:focus-visible) {
  outline-color: rgba(47, 128, 237, 0.72);
  box-shadow: 0 0 0 6px rgba(47, 128, 237, 0.18);
}

.paint-app {
  display: grid;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  height: 100vh;
  grid-template-rows: 56px 220px minmax(0, 1fr) 52px;
  overflow: hidden;
  color: var(--text);
  background: #f4f7fb;
}

.paint-app > * {
  min-width: 0;
  max-width: 100%;
}

.titlebar {
  display: flex;
  height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(18px, 5vw, 76px);
  color: #ffffff;
  background: rgba(12, 15, 16, 0.86);
  border-bottom: 1px solid rgba(248, 244, 232, 0.16);
  backdrop-filter: blur(22px);
}

.brand-link {
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand,
.brand-title,
.paint-nav,
.ribbon-group-body,
.color-panel,
.status-left,
.status-right,
.status-item,
.zoom-control {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  font-weight: 900;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #07100d;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), transparent 34%),
    linear-gradient(135deg, #6de1a6, #f5c45b);
  border: 1px solid rgba(248, 244, 232, 0.22);
  border-radius: 8px;
  box-shadow: 0 0 34px rgba(109, 225, 166, 0.22);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
}

.brand-title {
  align-items: flex-start;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  line-height: 1.05;
  white-space: nowrap;
}

.brand-title strong {
  font-size: 1rem;
}

.document-name {
  overflow: hidden;
  margin-top: 4px;
  color: #c4bdad;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  text-overflow: ellipsis;
}

.paint-nav {
  gap: 6px;
  color: #c4bdad;
  font-size: 0.92rem;
  font-weight: 850;
}

.paint-nav a,
.paint-nav button {
  display: flex;
  min-height: 44px;
  align-items: center;
  padding: 8px 10px;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  text-decoration: none;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}

.paint-nav a:hover,
.paint-nav button:hover {
  color: #f5c45b;
  background: rgba(248, 244, 232, 0.07);
  border-color: rgba(248, 244, 232, 0.14);
}

.paint-nav .nav-cta {
  color: #f8f4e8;
  background: rgba(109, 225, 166, 0.1);
  border-color: rgba(109, 225, 166, 0.22);
}

.ribbon {
  z-index: 2;
  display: grid;
  grid-template-rows: 64px 156px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.paint-mobile-instruction {
  display: none;
}

.tabs {
  display: flex;
  align-items: end;
  gap: 28px;
  padding: 0 28px;
  border-bottom: 1px solid #e4eaf3;
}

.tab {
  min-width: 56px;
  height: 64px;
  padding: 0 4px;
  color: #526174;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  font-size: 16px;
  font-weight: 600;
}

.tab.is-active {
  color: #0f3b75;
  border-bottom-color: var(--blue-600);
}

.ribbon-content {
  display: flex;
  width: 100%;
  align-items: stretch;
  gap: 14px;
  padding: 10px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.ribbon-content::-webkit-scrollbar {
  display: none;
}

.ribbon-group {
  display: grid;
  min-width: max-content;
  height: 136px;
  grid-template-rows: 1fr 26px;
  padding: 12px 16px 7px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border: 1px solid #d6dfec;
  border-radius: 12px;
}

.paint-app[data-active-tab="view"] .home-only,
.paint-app[data-active-tab="home"] .view-only {
  display: none;
}

.paint-app.is-minimized {
  grid-template-rows: 56px 0 minmax(0, 1fr) 52px;
}

.paint-app.is-minimized .ribbon {
  display: none;
}

.ribbon-group-body {
  gap: 12px;
  justify-content: center;
}

.ribbon-group-label {
  align-self: end;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.command-button,
.tool-button,
.shape-button,
.brush-size-button,
.mini-command-button,
.rail-button,
.zoom-button {
  color: #22324a;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
}

.command-button:hover,
.tool-button:hover,
.shape-button:hover,
.brush-size-button:hover,
.mini-command-button:hover,
.rail-button:hover,
.zoom-button:hover {
  background: #f2f7ff;
  border-color: #cfe0f8;
}

.tool-button.is-active,
.shape-button.is-active,
.brush-size-button.is-active,
.rail-button.is-active {
  color: #0d4f9c;
  background: var(--blue-100);
  border-color: #7db4ff;
  box-shadow: inset 0 0 0 1px rgba(47, 128, 237, 0.18);
}

.command-button {
  display: grid;
  width: 64px;
  height: 82px;
  grid-template-rows: 40px 1fr;
  place-items: center;
  font-size: 14px;
}

.command-icon,
.tool-icon {
  line-height: 1;
}

.command-icon {
  font-size: 32px;
}

.mini-command-stack {
  display: grid;
  gap: 6px;
}

.canvas-size-stack {
  display: grid;
  grid-template-columns: repeat(2, 84px) repeat(2, 64px);
  align-items: end;
  gap: 8px;
}

.canvas-size-stack.compact {
  grid-template-columns: repeat(2, 78px);
}

.size-label {
  display: grid;
  gap: 5px;
  color: #44546a;
  font-size: 12px;
  font-weight: 700;
}

.size-label input {
  width: 84px;
  min-height: 44px;
  height: 44px;
  padding: 0 8px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.size-action-button {
  min-height: 44px;
  height: 44px;
  color: #22324a;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.size-action-button:hover {
  background: #f2f7ff;
  border-color: #cfe0f8;
}

.mini-command-button {
  min-width: 82px;
  min-height: 44px;
  height: 44px;
  padding: 0 8px;
  color: #44546a;
  text-align: left;
}

.mini-command-button.is-disabled {
  color: var(--muted);
  background: rgba(95, 111, 133, 0.08);
  pointer-events: none;
}

.mini-command-button:disabled {
  color: var(--muted);
  background: rgba(95, 111, 133, 0.08);
  pointer-events: none;
}

.tool-button {
  display: grid;
  width: 70px;
  height: 86px;
  grid-template-rows: 42px 1fr;
  place-items: center;
  font-size: 14px;
}

.tool-icon {
  font-size: 34px;
}

.brush-size-options {
  gap: 6px;
}

.brush-size-button {
  display: grid;
  width: 64px;
  height: 60px;
  place-items: center;
}

.brush-dot.thin {
  width: 6px;
  height: 6px;
  background: #0f1f35;
  border-radius: 999px;
}

.brush-line {
  display: block;
  width: 34px;
  background: #0f1f35;
  border-radius: 999px;
}

.brush-line.small {
  height: 4px;
}

.brush-line.medium {
  height: 7px;
}

.brush-line.large {
  height: 10px;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 44px);
  grid-auto-rows: 44px;
  gap: 6px;
}

.shape-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  font-size: 25px;
}

.colors-group {
  width: max-content;
  flex: 0 0 auto;
  min-width: max-content;
}

.colors-group .ribbon-group-body {
  justify-content: flex-start;
  min-width: 0;
}

.color-panel {
  width: 100%;
  min-width: 0;
  gap: 14px;
}

.current-colors {
  flex: 0 0 82px;
  position: relative;
  width: 82px;
  height: 58px;
}

.current-color {
  position: absolute;
  width: 44px;
  height: 44px;
  background: #ffffff;
  border: 2px solid #ffffff;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 1px #9aa8bc;
}

.current-color.primary {
  top: 0;
  left: 0;
  z-index: 2;
  background: #000000;
}

.current-color.secondary {
  right: 8px;
  bottom: 0;
}

.swatches {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(10, 44px);
  grid-auto-rows: 44px;
  gap: 6px;
}

.swatch {
  width: 44px;
  height: 44px;
  background: var(--swatch);
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 8px;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.swatch:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}

.swatch.is-active {
  outline: 2px solid var(--blue-600);
  outline-offset: 2px;
}

.workspace {
  display: grid;
  min-height: clamp(360px, calc(100vh - 300px), 640px);
  grid-template-columns: 94px minmax(0, 1fr);
  background:
    linear-gradient(45deg, rgba(148, 163, 184, 0.1) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, 0.1) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, 0.1) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, 0.1) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.tool-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 22px 0 0 18px;
}

.tool-rail-panel {
  display: grid;
  gap: 9px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.rail-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  font-size: 23px;
}

.canvas-scroll {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: auto;
  padding: 32px 40px;
}

.canvas-stage {
  position: relative;
  width: min(1024px, calc(100vw - 220px), calc((100vh - 408px) * 4 / 3));
  min-width: 420px;
  aspect-ratio: var(--canvas-aspect, 4 / 3);
  background: #ffffff;
  border: 2px solid #cbd6e4;
  border-radius: var(--radius-md);
  box-shadow:
    0 22px 55px rgba(15, 23, 42, 0.16),
    0 3px 10px rgba(15, 23, 42, 0.1);
  transform-origin: center center;
}

.canvas-stage.is-resizing {
  transition: none;
  will-change: width;
}

.canvas-stage::before {
  position: absolute;
  inset: -14px;
  z-index: -1;
  background: var(--surface-soft);
  border: 1px solid #d4deeb;
  border-radius: 16px;
  content: "";
}

.resize-handle {
  position: absolute;
  right: -18px;
  bottom: -18px;
  width: 44px;
  height: 44px;
  background: #ffffff;
  border: 2px solid #aebbd0;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
  cursor: nwse-resize;
  z-index: 3;
  padding: 0;
}

.selection-box {
  position: absolute;
  border: 2px dashed #2f80ed;
  border-radius: 3px;
  background: rgba(47, 128, 237, 0.08);
  pointer-events: none;
}

#paintCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  touch-action: none;
}

.statusbar {
  display: flex;
  min-height: 52px;
  height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 16px;
  color: #26364d;
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.status-left,
.status-right {
  min-width: 0;
  gap: 22px;
}

.status-item {
  gap: 8px;
  white-space: nowrap;
}

.status-divider {
  width: 1px;
  height: 26px;
  background: var(--border);
}

.zoom-control {
  gap: 14px;
}

.zoom-button {
  width: 44px;
  height: 44px;
  font-size: 18px;
}

.zoom-slider {
  width: 170px;
  min-height: 44px;
  accent-color: var(--blue-600);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  .paint-app {
    grid-template-rows: 56px 220px minmax(0, 1fr) 40px;
  }

  .ribbon-content {
    overflow-x: auto;
  }

  .colors-group {
    flex: 0 0 470px;
  }
}

@media (max-width: 760px) {
  body .paint-app {
    height: 100dvh;
    max-width: 100vw;
    grid-template-rows: auto auto auto minmax(138px, 24dvh) minmax(300px, 1fr) auto auto auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .brand-title strong {
    font-size: 17px;
  }

  .document-name,
  .status-left {
    display: none;
  }

  .titlebar {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
    min-height: 84px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .paint-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .paint-nav::-webkit-scrollbar {
    display: none;
  }

  .paint-nav a,
  .paint-nav button {
    min-height: 44px;
    flex: 0 0 auto;
  }

  .paint-app .demo-overview {
    gap: 10px;
    margin-bottom: 8px;
    padding: 10px;
  }

  .paint-app .demo-overview h1 {
    font-size: 1.55rem;
  }

  .paint-app .demo-overview p,
  .paint-app .demo-overview dd {
    font-size: 0.82rem;
  }

  .paint-app .demo-overview-actions {
    display: flex;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .paint-app .demo-overview-actions::-webkit-scrollbar {
    display: none;
  }

  .paint-app .demo-overview-actions a,
  .paint-app .demo-overview-actions button {
    flex: 0 0 auto;
    min-height: 44px;
  }

  .paint-app .demo-control-list {
    display: none;
  }

  .ribbon {
    grid-template-rows: 48px auto minmax(0, 1fr);
    min-height: 138px;
    max-height: 24dvh;
    overflow: hidden;
  }

  .tabs {
    gap: 16px;
    overflow-x: auto;
    padding: 0 12px;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    min-width: 76px;
    min-height: 44px;
    height: 48px;
    font-size: 14px;
  }

  .paint-mobile-instruction {
    display: block;
    margin: 0;
    padding: 7px 12px 6px;
    color: #41516a;
    background: #eef6ff;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.35;
  }

  .ribbon-content {
    max-width: 100vw;
    align-items: start;
    gap: 8px;
    padding: 8px 10px 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-padding-inline: 10px;
    scroll-snap-type: x proximity;
  }

  .ribbon-group {
    height: auto;
    min-height: 82px;
    max-height: calc(24dvh - 58px);
    grid-template-rows: minmax(0, 1fr) 18px;
    padding: 8px;
    overflow: auto;
    border-radius: 10px;
    scroll-snap-align: start;
  }

  .ribbon-group-body {
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
  }

  .ribbon-group-label {
    font-size: 11px;
  }

  .command-button,
  .tool-button,
  .shape-button,
  .brush-size-button,
  .mini-command-button,
  .rail-button,
  .zoom-button,
  .size-action-button,
  .swatch {
    min-width: 44px;
    min-height: 44px;
  }

  .command-button {
    width: 54px;
    height: 54px;
    grid-template-rows: 26px 1fr;
    font-size: 11px;
  }

  .command-icon {
    font-size: 24px;
  }

  .tool-button {
    width: 58px;
    height: 58px;
    grid-template-rows: 30px 1fr;
    font-size: 11px;
  }

  .tool-icon {
    font-size: 25px;
  }

  .mini-command-button {
    height: 44px;
    min-width: 88px;
    text-align: center;
  }

  .brush-size-button {
    width: 46px;
    height: 44px;
  }

  .shape-grid {
    grid-template-columns: repeat(4, 44px);
    grid-auto-rows: 44px;
    gap: 6px;
  }

  .shape-button {
    width: 44px;
    height: 44px;
    font-size: 23px;
  }

  .colors-group {
    width: min(92vw, 390px);
    min-width: min(92vw, 390px);
    flex: 0 0 min(92vw, 390px);
  }

  .color-panel {
    align-items: flex-start;
    gap: 10px;
  }

  .current-colors {
    flex-basis: 70px;
    width: 70px;
    height: 54px;
  }

  .current-color {
    width: 42px;
    height: 42px;
  }

  .swatches {
    grid-template-columns: repeat(5, 44px);
    grid-auto-rows: 44px;
    gap: 6px;
    max-height: 94px;
    overflow: auto;
  }

  .swatch {
    width: 44px;
    height: 44px;
    border-radius: 8px;
  }

  .canvas-size-stack,
  .canvas-size-stack.compact {
    grid-template-columns: repeat(2, minmax(82px, 1fr));
    gap: 8px;
  }

  .size-label input,
  .size-action-button {
    width: 100%;
    height: 44px;
  }

  .workspace {
    min-height: 300px;
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .tool-rail {
    gap: 10px;
    padding: 12px 0 0 8px;
  }

  .tool-rail-panel {
    gap: 7px;
    padding: 7px;
  }

  .rail-button {
    width: 44px;
    height: 44px;
    font-size: 21px;
  }

  .canvas-scroll {
    padding: 18px 14px;
    overflow: auto;
  }

  .canvas-stage {
    width: min(1024px, calc(100vw - 96px), calc((100dvh - 360px) * 4 / 3));
    min-width: 220px;
  }

  .resize-handle {
    right: -18px;
    bottom: -18px;
    width: 44px;
    height: 44px;
    border-width: 2px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
  }

  .statusbar {
    min-height: 52px;
    height: auto;
    padding: 6px 10px;
  }

  .status-right {
    width: 100%;
    justify-content: center;
  }

  .zoom-control {
    width: min(100%, 360px);
    gap: 10px;
  }

  .zoom-button {
    width: 44px;
    height: 44px;
  }

  .zoom-slider {
    width: min(38vw, 150px);
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .swatch:hover,
  .command-button:hover,
  .tool-button:hover,
  .shape-button:hover,
  .brush-size-button:hover,
  .mini-command-button:hover,
  .rail-button:hover,
  .zoom-button:hover,
  .size-action-button:hover {
    transform: none;
  }
}
