:root {
  --page: #f4efe5;
  --panel: #ffffff;
  --ink: #302a22;
  --muted: #6c6458;
  --border: #d8cdb9;
  --accent: #7b5b32;
  --success: #2f6b4f;
  --error: #9c2f2f;
  --highlight: #f0a51a;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--page);
}

button { font: inherit; }

.site-header {
  padding: 0.75rem 1rem 0.65rem;
  text-align: center;
}

.home-link {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-decoration: none;
}

.site-header h1 {
  margin: 0.18rem 0 0;
  font-size: clamp(1.7rem, 3vw, 2.5rem);
}

.site-header p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(285px, 340px) minmax(0, 1fr);
  gap: 0.8rem;
  padding: 0 0.8rem 0.8rem;
  min-height: calc(100vh - 96px);
}

.control-panel,
.art-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.control-panel {
  position: sticky;
  top: 0.5rem;
  padding: 0.85rem;
  align-self: start;
  max-height: calc(100vh - 1rem);
  overflow-y: auto;
}

.control-panel h2 {
  margin: 0 0 0.45rem;
  font-size: 1.02rem;
}

.instructions {
  margin: 0 0 0.85rem 1.1rem;
  padding: 0;
  font-size: 0.9rem;
}

.instructions li { margin-bottom: 0.3rem; }

.status-box {
  margin-bottom: 0.85rem;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fcfaf5;
  font-size: 0.9rem;
}

.status-box p { margin: 0.22rem 0; }

.message {
  min-height: 1.2em;
  font-weight: 700;
}

.message.success { color: var(--success); }
.message.error { color: var(--error); }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.outline-note {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: right;
}

.palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.color-button,
.quick-color-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.color-button {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem;
  min-width: 0;
  border-radius: 8px;
  text-align: left;
}

.color-button:hover,
.color-button:focus-visible,
.quick-color-button:hover,
.quick-color-button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.color-button.selected,
.quick-color-button.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123,91,50,0.18);
}

.swatch {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 6px;
}

.color-copy {
  min-width: 0;
  font-size: 0.76rem;
  line-height: 1.1;
}

.color-copy strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remaining-count {
  min-width: 1.95rem;
  padding: 0.16rem 0.38rem;
  border-radius: 999px;
  background: #6E543B;
  color: #FFFFFF;
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  border: 1px solid rgba(0,0,0,0.08);
}

.remaining-count.zero {
  background: #E9E1D5;
  color: #4E4539;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.actions button,
.toolbar button,
.modal-card button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-weight: 700;
}

.actions button:hover,
.toolbar button:hover,
.modal-card button:hover { filter: brightness(1.06); }

.actions button[aria-pressed="true"] { background: #3e6e63; }

.art-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
  background: #fbf8f2;
}

.tool-buttons {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.toolbar button[aria-pressed="true"] { background: #3e6e63; }

.zoom-label {
  min-width: 3.4rem;
  text-align: center;
  font-weight: 700;
}

.quick-palette-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.quick-palette-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}


.quick-color-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.45rem;
  border-radius: 8px;
  white-space: nowrap;
}

.quick-color-button > span:nth-child(2) {
  font-weight: 800;
  color: #3C3328;
}

.quick-color-button .swatch {
  width: 24px;
  height: 24px;
}

.quick-palette {
  display: flex;
  gap: 0.35rem;
  min-width: 0;
  padding: 0.18rem 0.12rem 0.28rem;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.quick-color-button {
  display: grid;
  grid-template-columns: 24px auto auto;
  align-items: center;
  gap: 0.28rem;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0.25rem 0.38rem;
  border-radius: 8px;
  font-size: 0.77rem;
  font-weight: 800;
}

.quick-color-button .swatch {
  width: 24px;
  height: 24px;
  border-radius: 5px;
}

.quick-color-button .remaining-count {
  min-width: 1.45rem;
  font-size: 0.68rem;
}

.art-viewport {
  flex: 1;
  min-height: 520px;
  overflow: auto;
  padding: 0.6rem;
  background:
    linear-gradient(45deg, #f2f2f2 25%, transparent 25%),
    linear-gradient(-45deg, #f2f2f2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f2f2 75%),
    linear-gradient(-45deg, transparent 75%, #f2f2f2 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

.art-viewport.pan-mode {
  cursor: grab;
  user-select: none;
}

.art-viewport.pan-mode.dragging { cursor: grabbing; }

.art-stage {
  position: relative;
  width: 720px;
  margin: 0;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.16), 0 4px 14px rgba(0,0,0,0.12);
}

.svg-container,
.svg-container svg,
.line-overlay,
.selection-overlay {
  display: block;
  width: 100%;
  height: auto;
}

.svg-container { position: relative; z-index: 1; }

.line-overlay,
.selection-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.line-overlay { z-index: 3; }
.selection-overlay { z-index: 4; overflow: visible; }

.paint-region { cursor: pointer; }
.paint-region.companion { pointer-events: none; }
.paint-label { pointer-events: none; user-select: none; }

.art-stage.showing-solution .paint-label { opacity: 0; }
.art-stage.showing-solution .selection-overlay { display: none; }

.art-viewport.pan-mode .art-stage { pointer-events: none; }

.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0,0,0,0.5);
}

.modal-card {
  width: min(380px, 100%);
  padding: 1.2rem;
  border-radius: 12px;
  background: #fff;
  text-align: center;
}

.modal-card h2 { margin-top: 0; }

:fullscreen .art-viewport { min-height: calc(100vh - 118px); }
:fullscreen .toolbar { top: 0; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel {
    position: static;
    max-height: none;
  }
  .art-viewport { min-height: 70vh; }
}

@media (max-width: 520px) {
  .palette { grid-template-columns: 1fr; }
  .quick-palette-label { display: none; }
  .quick-palette-wrap { grid-template-columns: minmax(0, 1fr); }
  .tool-buttons { gap: 0.3rem; }
  .toolbar button { padding: 0.48rem 0.58rem; }
}


/* Version 4.3: keep artwork close to the controls instead of centering it in wide viewports. */
.art-viewport { scroll-padding: 0.6rem; }

/* The completion dialog is moved into the active fullscreen element by JavaScript. */
:fullscreen .modal { position: fixed; inset: 0; z-index: 1000; }

.device-note {
  margin: -0.35rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
