:root {
  color-scheme: light;
  --ink: #271e34;
  --muted: #655c70;
  --accent: #563782;
  --accent-dark: #432765;
  --tint: #eee7fa;
  --line: #ded6e5;
  --paper: #fffcf8;
  font-family: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #f7f3f4;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(ellipse at 7% 6%, #f6e9df, transparent 44%),
    radial-gradient(ellipse at 100% 0%, #ece1fa, transparent 54%);
}
[hidden] { display: none !important; }

main {
  max-width: 1120px;
  margin-inline: auto;
  padding: 0 clamp(14px, 4vw, 44px) 48px;
}

.masthead {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);
  align-items: center;
  gap: 5px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 750;
}
.masthead a, .game-play-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding-inline: 4px;
  color: var(--accent-dark);
  text-decoration: none;
  font-size: 13px;
}
.masthead a:hover { text-decoration: underline; }
.game-brand { justify-self: start; }
.game-brand img { border-radius: 6px; }
.game-guide-link { justify-self: end; }
.masthead .game-rank-link, .game-play-link {
  padding-inline: 9px;
  border: 1px solid #d2bee3;
  border-radius: 10px;
  background: var(--tint);
}
.masthead .game-rank-link, .actions #rank-link {
  color: #fff;
  border-color: #126252;
  background: #126252;
}
.masthead .game-rank-link:hover, .actions #rank-link:hover { background: #0d5144; }
.game-rank-link .icon, #rank-link .icon { color: #ffe3a0; }
.game-play-link { margin-top: 12px; font-weight: 650; }
.masthead .icon, .game-play-link .icon { width: 17px; height: 17px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, .85fr) minmax(0, 1.4fr);
  align-items: start;
  gap: clamp(24px, 5vw, 62px);
  margin-top: clamp(20px, 5vw, 50px);
}
.sidebar { min-width: 0; }
h1, h2 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 500;
  letter-spacing: -.045em;
}
h1 {
  margin: 0 0 12px;
  font-size: clamp(2.5rem, 5.2vw, 4.1rem);
  line-height: .99;
}
.intro p, .guide p {
  color: var(--muted);
  line-height: 1.55;
  text-align: justify;
  text-align-last: start;
  overflow-wrap: anywhere;
}
.intro p { margin: 0 0 20px; }

button, input { font: inherit; color: inherit; }
button {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
  touch-action: manipulation;
}
button:disabled { opacity: .48; cursor: default; }
:where(button, input, a, summary):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
@media (hover: hover) {
  button:not(:disabled):hover { border-color: #ad96c5; }
}
button:not(:disabled):active { transform: scale(.98); }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }

.modes { display: grid; gap: 8px; }
.mode-symbol {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--tint); color: var(--accent); font-size: 20px;
}
.modes button[aria-pressed="true"] .mode-symbol { background: #ffffff21; color: white; }
.modes button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 13px;
  text-align: left;
}
.modes .icon {
  width: 36px;
  height: 36px;
  padding: 8px;
  border-radius: 10px;
  background: var(--tint);
  color: var(--accent);
}
.modes button[aria-pressed="true"] {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: white;
  box-shadow: 0 4px 12px #43276526;
}
.modes button[aria-pressed="true"] .icon { background: #ffffff21; color: #fff; }
.modes strong, .modes small { display: block; }
.modes strong { font-size: 14px; }
.modes small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.modes button[aria-pressed="true"] small { color: #eee1ff; }

#tutorial {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-inline: 9px;
  color: var(--accent-dark);
  background: transparent;
  border-color: transparent;
  font-size: 13px;
  font-weight: 650;
}

.game {
  min-width: 0;
  container-type: inline-size;
  padding: clamp(10px, 2.7vw, 24px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: clamp(18px, 3vw, 28px);
  box-shadow: 0 16px 52px #3e254913, 0 3px 8px #3e254908;
}
.bar { display: grid; gap: 8px; margin-bottom: 12px; }
.sessions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 4px;
  border-radius: 14px;
  background: #f1eaf3;
}
.sessions.has-challenge { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sessions button {
  padding-inline: 2px;
  border-color: transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.sessions button[aria-pressed="true"] {
  background: white;
  border-color: #e0d3e7;
  color: var(--accent-dark);
  box-shadow: 0 1px 3px #3e254916;
}
#count {
  justify-self: end;
  padding: 4px 9px;
  border-radius: 7px;
  background: #f1eaf3;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#archive-date {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}
#date { width: auto; max-width: 100%; }

.board-stage {
  padding: clamp(6px, 1.7vw, 16px);
  border-radius: 18px;
  border: 1px solid #e5ddeb;
  background: #f5eff7;
}
.field, .strip { display: grid; gap: clamp(4px, .75vw, 8px); margin-inline: auto; }
.field { width: min(100%, 330px); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mosaic { display: grid; width: min(100%, 400px); margin-inline: auto; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px; }
.mosaic .tile { aspect-ratio: 1; }
.mosaic .tile.selected { transform: none; }
.field.tutorial { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.strip { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.tile {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: clamp(6px, 1vw, 12px);
  box-shadow: inset 0 0 0 1px #22192e23;
}
.field .tile { aspect-ratio: 1; }
.strip .tile { min-height: 146px; }
.tile:disabled { opacity: 1; }
.tile.selected {
  box-shadow: inset 0 0 0 3px #261735, inset 0 0 0 6px white;
  transform: scale(.96);
}
.tile:focus-visible { z-index: 1; }
.tile.fixed::after, .tile.hinted::before, .tile.hint-partner::before, .tile-position {
  position: absolute;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #261735;
  color: white;
  font-size: 11px;
  box-shadow: 0 0 0 1px #ffffffa6;
}
.tile.fixed::after { content: '◆'; top: 50%; left: 50%; translate: -50% -50%; }
.tile.hinted::before { content: '!'; top: 6px; left: 6px; font-weight: 750; }
.tile.hint-partner::before { content: '+'; top: 6px; left: 6px; background: #fff; color: #261735; font-weight: 750; }
.tile-position { right: 5px; bottom: 5px; display: none; font-variant-numeric: tabular-nums; }
#strip-order { display: none; margin: 8px 0 0; font-size: 12px; color: var(--muted); }

.sample {
  min-height: 150px;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px #22192e26;
}
#form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  margin-top: 12px;
}
#form label { display: grid; gap: 4px; font-size: 13px; font-weight: 650; }
input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #b9a9c5;
  border-radius: 10px;
  background: #fff;
}
#form button { padding-inline: 12px; background: var(--accent-dark); color: white; }
#guess, #history, #link { font-family: "IBM Plex Mono", Consolas, monospace; }
#history { padding-left: 25px; font-size: clamp(11px, 2.8vw, 13px); }
#history:empty { display: none; }
#history li { margin: 5px 0; }
.guess-color {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  margin-inline-end: .5em;
  border: 1px solid #a18eae;
  border-radius: 4px;
  vertical-align: middle;
}

#status {
  min-height: 39px;
  margin: 9px 0;
  padding: 7px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
#status[data-result="won"] {
  padding-inline: 10px;
  border-radius: 8px;
  color: #215444;
  background: #e6f4e9;
  font-weight: 650;
}
#status[data-result="lost"] { color: #8b3c4e; }
.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.actions button, .actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  padding: 5px 2px;
  font-size: 12px;
  font-weight: 650;
}
.actions a {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--accent-dark);
  background: var(--paper);
  text-decoration: none;
}
.actions a:hover { background: #efe5f7; }
.actions a:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 2px; }
.actions .icon { width: 17px; height: 17px; }
#next { color: white; border-color: var(--accent-dark); background: var(--accent-dark); }
#next:hover { background: var(--accent); }
#share-panel { margin-top: 10px; }
.share-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.share-controls button { padding-inline: 10px; }
#link { font-size: 13px; }
.game-note { margin: 6px 0 10px; font-size: 12px; color: var(--muted); text-align: justify; text-align-last: start; }
#submit-daily { width: min(390px, calc(100% - 20px)); padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); }
#submit-daily::backdrop { background: #26173566; }
#submit-daily h2 { font-size: 1.25rem; margin: 0; }
#submit-daily p { margin: 6px 0; font-size: 13px; }
.submit-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.submit-actions button[value="submit"] { background: var(--accent-dark); color: white; }

.guide { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); }
.guide h2 { margin: 0; font-size: 2rem; }
.guide details { border-top: 1px solid var(--line); }
.guide summary { min-height: 44px; padding: 12px 0; cursor: pointer; font-weight: 650; }
.guide details p { margin-top: 0; }

@media (max-width: 760px) {
  .masthead { min-height: 49px; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 16px; }
  .sidebar { display: contents; }
  h1 { font-size: clamp(2rem, 7vw, 2.65rem); margin-bottom: 6px; }
  .intro p { margin-bottom: 0; font-size: 14px; }
  .modes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .modes button { justify-content: center; gap: 4px; min-height: 44px; padding: 3px; }
  .modes .icon { width: 19px; height: 19px; padding: 0; background: transparent; }
  .modes button[aria-pressed="true"] .icon { background: transparent; }
  .modes strong { font-size: 12px; }
  .modes .mode-symbol { width: 19px; height: 19px; background: transparent; }
  .modes button[aria-pressed="true"] .mode-symbol { background: transparent; }
  .modes small { display: none; }
  .field { width: min(100%, 310px); }
}

@container (max-width: 414px) {
  .strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .strip .tile { min-height: 56px; }
  .tile-position { display: grid; }
  #strip-order { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

[data-embed] .masthead, [data-embed] .guide { display: none; }
[data-embed] main { padding: 14px clamp(10px, 2vw, 20px) 16px; }
[data-embed] .workspace { margin-top: 0; gap: clamp(10px, 4vw, 48px); }
[data-embed] .field { width: min(100%, 280px); }
[data-embed] h1 { font-size: clamp(2rem, 4.5vw, 3rem); }

@media (max-width: 760px) {
  [data-embed] .workspace { gap: 8px; }
  [data-embed] h1 { font-size: clamp(1.5rem, 6vw, 2rem); }
}

[data-compact] main { padding: 4px 6px 12px; }
[data-compact] .game {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
[data-compact] .board-stage { padding: 0; border: 0; background: transparent; }
[data-compact] .strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
[data-compact] .strip .tile { min-height: 46px; }
[data-compact] .tile-position { display: grid; }
[data-compact] #strip-order { display: none; }
[data-compact] .field { width: min(100%, 200px); }
[data-compact] .sample { min-height: 54px; }
[data-compact] #status {
  min-height: 18px;
  margin: 2px 0;
  padding: 0 4px;
  font-size: 12px;
  line-height: 18px;
}
[data-compact] .actions button, [data-compact] .actions a {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 1px;
  font-size: 11px;
}
[data-compact] .bar { margin: 10px 0 6px; }
[data-compact] .bar #count { display: none; }
[data-compact] .sidebar { display: block; padding-top: 10px; border-top: 1px solid var(--line); }
[data-compact] .sidebar .intro { margin-bottom: 8px; }
[data-compact] #form { margin-top: 4px; }
