/* Beach layouts - four reusable tablet cards. Pure white task surfaces, navy identity. */
:root {
  --navy: #174A7E;
  --navy-deep: #103a63;
  --pale: #D2F9F6;
  --pale-2: #EDFCFA;
  --ink: #14202e;
  --line: rgba(23, 74, 126, 0.28);
  --shadow: 0 10px 24px rgba(16, 34, 56, 0.14);
  --gap: clamp(8px, 1.3vw, 16px);
  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; }

.cardnav { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.cardnav button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 44px; padding: 6px 12px; border-radius: 12px;
  border: 2px solid var(--navy);
  background: #fff; color: var(--navy);
  font: inherit; font-size: .82rem; cursor: pointer;
}
.cardnav button:hover { background: var(--pale-2); }
.cardnav button[aria-current="true"] {
  background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 700;
}
.cn-dots { letter-spacing: 2px; font-size: .7rem; opacity: .9; }

.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); }

/* ------------------------------------------------------------ scene */
.scene {
  --band: 250px;
  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: 44vh;
  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.6vw, 18px);
  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;
}

/* ------------------------------------------------------------ mats */
.mats {
  --mat-h: max(140px, calc(100dvh - var(--band, 200px) - 290px));
  --mat-max: min(340px, var(--mat-h));
  display: flex; flex-direction: column; align-items: center; gap: var(--gap);
  width: 100%; padding-top: 12px;
}
.mats.own-creating { --mat-h: max(140px, calc(100dvh - var(--band, 200px) - 300px)); }
.mats.own-copy { --mat-h: max(140px, calc(100dvh - var(--band, 200px) - 420px)); }
.row { display: grid; gap: var(--gap); justify-content: center; align-items: start; width: 100%; }
.mode-choice .row { grid-template-columns: repeat(4, minmax(0, var(--mat-max))); }
.mode-fix .row { grid-template-columns: repeat(2, minmax(0, var(--mat-max))); }
.own { display: flex; flex-direction: column; align-items: center; gap: var(--gap); width: 100%; }
.own-creating .own { flex-direction: row; align-items: flex-start; justify-content: center; }
.own .pair { display: grid; grid-template-columns: repeat(2, minmax(0, var(--mat-max))); gap: var(--gap); justify-content: center; }
.own .pair .mat { width: 100%; }
.own > .mat { width: var(--mat-max); max-width: 100%; flex: 0 0 auto; }

.mat {
  position: relative; width: 100%;
  padding: clamp(6px, 1.1vw, 14px); border-radius: 20px;
  background: #ffffff;
  border: 3px solid var(--navy);
  box-shadow: var(--shadow);
}
button.mat { font: inherit; color: inherit; text-align: center; cursor: pointer; touch-action: manipulation; }
button.mat:hover { border-color: var(--navy-deep); }
.mat-cap {
  position: absolute; top: -13px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; font-size: .72rem; font-weight: 700;
  letter-spacing: .3px; padding: 3px 12px; border-radius: 999px; white-space: nowrap;
}
.mat.is-sample .mat-cap { background: var(--navy-deep); }
.mat.is-chosen { outline: 4px solid var(--navy); outline-offset: 4px; }
.mat.is-frozen .mat-cap { background: var(--navy); }

.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.8vw, 10px);
}
button.cell { font: inherit; cursor: pointer; touch-action: none; }
.cell.is-selected { outline: 3px solid var(--navy); outline-offset: -3px; }
.cell.is-source { outline: 3px dashed var(--navy); outline-offset: -3px; }
.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%; }
.ghost-piece { position: fixed; width: 96px; height: 96px; z-index: 40; pointer-events: none; opacity: .92; }

.tray {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center;
  padding: 8px 12px; border-radius: 16px; background: #ffffff;
  border: 3px solid var(--navy); box-shadow: var(--shadow);
  width: fit-content; max-width: 100%;
}
.tray-cap { font-weight: 700; color: var(--navy-deep); font-size: .82rem; text-align: center; }
.tray button {
  display: flex; align-items: center; justify-content: center;
  width: clamp(52px, 11vw, 76px); aspect-ratio: 1/1; padding: 6px;
  border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer;
  touch-action: none;
}
.tray button.is-selected { outline: 3px solid var(--navy); outline-offset: -3px; }

.feedback {
  margin: 0; text-align: center; min-height: 1.4em; font-size: clamp(.86rem, 1.4vw, 1rem);
  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; }
  .cardnav { width: 100%; margin-left: 0; justify-content: space-between; }
  .cardnav button { flex: 1; padding: 6px 4px; font-size: .74rem; }
  .bottombar .primary { order: -1; width: 100%; margin-left: 0; }
  .mode-choice .row { grid-template-columns: repeat(2, minmax(0, var(--mat-max))); }
  .own-creating .own { flex-direction: column; align-items: center; }
}

@media (max-height: 700px) {
  .work-head h1 { font-size: 1.1rem; }
  .work-head p { font-size: .82rem; }
}

@media (max-height: 500px) {
  .scene { --band: 90px; }
  .work { gap: 6px; padding-top: calc(var(--band) + 2px); }
  .tray { padding: 6px 10px; gap: 6px; }
  .tray-cap { display: none; }
  .tray button { width: 46px; }
}
