/* What switched places? - one tablet card, three trials. White task surfaces, navy identity. */
:root {
  --navy: #174A7E;
  --navy-deep: #174A7E;
  --pale-2: #EDFCFA;
  --ink: #14202e;
  --line: rgba(23, 74, 126, 0.28);
  --shadow: 0 10px 24px rgba(16, 34, 56, 0.14);
  --gap: clamp(10px, 1.6vw, 20px);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background: #ffffff;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Verdana, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

.skip {
  position: absolute; left: -999px; top: 0; background: var(--navy); color: #fff;
  padding: 10px 16px; z-index: 50; border-radius: 0 0 10px 0;
}
.skip:focus { left: 0; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto auto;
  background: #ffffff;
}

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px clamp(10px, 2vw, 22px);
  background: #ffffff;
  color: var(--navy);
  border-bottom: 3px solid var(--navy);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.ori {
  width: 42px; height: 42px; border-radius: 50%;
  background: #fff; object-fit: cover; border: 2px solid var(--navy);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.02rem; letter-spacing: .2px; color: var(--navy-deep); }
.brand-text span { font-size: .78rem; opacity: .78; }
#info-toggle { margin-left: auto; }

.ghost {
  min-height: 44px; padding: 8px 14px; border-radius: 12px;
  border: 2px solid var(--navy); background: #fff; color: var(--navy);
  font: inherit; font-weight: 600; cursor: pointer;
}
.ghost:hover:not(:disabled) { background: var(--pale-2); }
.ghost:disabled { opacity: .4; cursor: default; }
.ghost[aria-pressed="true"] { background: var(--navy); color: #fff; }
.primary {
  min-height: 48px; padding: 10px 22px; border-radius: 14px; border: 2px solid var(--navy);
  background: var(--navy); color: #fff; font: inherit; font-size: 1.02rem; font-weight: 700;
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.primary:hover { background: var(--navy-deep); }
.primary:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.primary:focus-visible, .topbar :focus-visible { outline-color: var(--pale-2); }

/* ------------------------------------------------------------ scene */
.scene {
  --band: 200px;
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  min-height: 0;
  background: #ffffff;
}
.scene-bg {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: min(750px, 100%); height: auto; max-height: 40vh;
  object-fit: contain; object-position: top center;
  z-index: 0; user-select: none;
}
.work {
  position: relative; z-index: 1; width: 100%; max-width: 1180px;
  padding: calc(var(--band) + 4px) clamp(8px, 1.8vw, 20px) clamp(8px, 1.4vw, 16px);
  display: flex; flex-direction: column; gap: var(--gap);
}
.work-head { text-align: center; }
.work-head h1 {
  margin: 0; font-size: clamp(1.15rem, 2.4vw, 1.75rem); color: var(--navy-deep);
}
.work-head p {
  margin: 3px auto 0; max-width: 52ch; font-size: clamp(.85rem, 1.4vw, 1rem);
  color: #24384d;
}
.done {
  display: inline-block; margin-top: 5px; padding: 3px 12px; border-radius: 999px;
  background: var(--navy); color: #fff; font-size: .8rem; font-weight: 700;
}

/* ------------------------------------------------------------ two large mats */
.mats {
  --mat-h: max(150px, calc(100dvh - var(--band, 200px) - 320px));
  --mat-max: min(430px, var(--mat-h));
  display: flex; flex-direction: column; align-items: center; gap: var(--gap);
  width: 100%; padding-top: 8px;
}
.row {
  display: grid; gap: clamp(12px, 3vw, 40px);
  grid-template-columns: repeat(2, minmax(0, var(--mat-max)));
  justify-content: center; align-items: start; width: 100%;
}

.mat {
  position: relative; width: 100%;
  padding: clamp(6px, 1vw, 12px); border-radius: 18px;
  background: #ffffff;
  border: 3px solid var(--navy);
  box-shadow: var(--shadow);
}
.mat-cap {
  position: absolute; top: -13px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; font-size: .76rem; font-weight: 700;
  letter-spacing: .3px; padding: 3px 12px; border-radius: 999px; white-space: nowrap;
}
.mat.is-sample .mat-cap { background: var(--navy-deep); }

.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
  background: var(--navy);
  border-radius: 12px; padding: 3px;
}
.cell {
  position: relative; aspect-ratio: 1 / 1; border-radius: 9px;
  background: #ffffff; border: none;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(4px, 0.9vw, 12px);
}
button.cell { font: inherit; cursor: pointer; touch-action: manipulation; }
button.cell:hover { background: var(--pale-2); }
/* A thin marking outline plus an unmistakable check: the chosen piece reads instantly. */
.cell.is-selected { outline: 3px solid var(--navy); outline-offset: -3px; background: var(--pale-2); }
.cell.is-selected::after {
  content: "✓"; position: absolute; top: 4px; right: 4px;
  width: clamp(22px, 22%, 30px); aspect-ratio: 1 / 1; border-radius: 50%;
  background: var(--navy); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(.8rem, 1.6vw, 1.05rem); line-height: 1;
}
.piece {
  width: 100%; height: 100%;
  background-image: url("assets/beach-props.webp");
  background-size: 200% 200%; background-repeat: no-repeat;
  filter: drop-shadow(0 3px 3px rgba(16, 34, 56, .16));
}
.piece-s { background-position: 0% 0%; }
.piece-t { background-position: 100% 0%; }
.piece-p { background-position: 0% 100%; }
.piece-d { background-position: 100% 100%; }

.feedback {
  margin: 0; text-align: center; min-height: 1.4em; font-size: clamp(.88rem, 1.4vw, 1.02rem);
  font-weight: 600; color: var(--navy-deep);
}
.feedback[data-tone="good"] { color: var(--navy); }
.feedback[data-tone="calm"] { color: #8a4a12; }

/* ------------------------------------------------------------ ink canvas */
.ink {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: 2; pointer-events: none; touch-action: none;
}
body[data-tool="pen"] .ink, body[data-tool="line"] .ink, body[data-tool="eraser"] .ink { pointer-events: auto; }
body[data-tool="pen"] .mats, body[data-tool="line"] .mats, body[data-tool="eraser"] .mats { pointer-events: none; }

/* ------------------------------------------------------------ drawing bar (in flow, never hides the mats) */
.drawbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  width: min(760px, calc(100% - 20px)); margin: 0 auto 6px;
  padding: 8px 14px; border-radius: 16px;
  background: #ffffff; border: 3px solid var(--navy); box-shadow: var(--shadow);
  position: sticky; bottom: 0; z-index: 6;
}
.toolgroup { display: flex; gap: 6px; }
.toolgroup button {
  min-height: 44px; padding: 6px 14px; border-radius: 12px; border: 2px solid var(--navy);
  background: #fff; color: var(--navy); font: inherit; font-weight: 600; cursor: pointer;
}
.toolgroup button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--navy); }
.size { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--navy-deep); }
.size input { width: 120px; min-height: 44px; }

/* ------------------------------------------------------------ bottom bar */
.bottombar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px clamp(10px, 2vw, 22px);
  background: #ffffff;
  border-top: 3px solid var(--navy);
  position: relative; z-index: 5;
}
.pager { display: flex; align-items: center; gap: 10px; }
.pager-label { font-weight: 700; color: var(--navy-deep); min-width: 8ch; text-align: center; }
.save-status { font-size: .78rem; color: #8a4a12; max-width: 46ch; }
.bottombar .primary { margin-left: auto; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------ dialogs */
dialog.sheet {
  border: 3px solid var(--navy); border-radius: 20px; padding: 22px 24px; max-width: min(560px, 92vw);
  background: #ffffff;
  box-shadow: 0 20px 60px rgba(10, 24, 40, .3); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(12, 30, 48, .45); }
dialog.sheet h2 { margin: 0 0 8px; color: var(--navy-deep); }
dialog.sheet p { margin: 0 0 14px; line-height: 1.5; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
#picture-preview { max-width: 100%; max-height: 46vh; border-radius: 12px; border: 2px solid var(--line); display: block; margin: 0 auto 14px; }

/* ------------------------------------------------------------ narrow / short screens */
@media (max-width:800px), (max-width:1000px) and (max-height:500px) {
  .drawbar { position: static; }
  .brand-text span { display: none; }
  .bottombar .primary { order: -1; width: 100%; margin-left: 0; }
  .row { gap: 10px; }
  .mat-cap { font-size: .68rem; padding: 2px 9px; }
}

@media (max-height: 700px) {
  .work-head h1 { font-size: 1.15rem; }
  .work-head p { font-size: .84rem; }
  .scene { --band: 120px; }
}

/* Rotated phones (short landscape): small corner art, tight bands, one footer row. */
@media (max-height: 500px) and (min-width: 561px) {
  .scene-bg {
    left: 75px; top: 0; transform: none;
    width: 130px; height: auto; max-height: 130px;
  }
  .work { padding: 8px clamp(8px, 1.8vw, 20px) 6px; gap: 6px; }
  .work-head { position: relative; }
  .work-head h1 { font-size: 18px; }
  .work-head p { font-size: 13px; margin-top: 1px; }
  .done { position: absolute; top: 4px; right: 8px; margin-top: 0; }
  .mats { --mat-max: 180px; padding-top: 12px; gap: 6px; }
  .feedback:empty { display: none; }
  .bottombar { gap: 6px; padding: 4px 8px; font-size: 12px; }
  .bottombar .ghost { padding: 6px 8px; min-height: 44px; }
  .bottombar .primary { font-size: 13px; padding: 6px 10px; min-height: 44px; }
  .bottombar .pager { gap: 6px; }
  .bottombar .tools { gap: 6px; }
}
