:root {
  color-scheme: light;
  --ink: #12364a;
  --paper: #f7efd8;
  --water: #b9e9e7;
  --coral: #f5876e;
  --amber: #e4a43a;
  --white: #fffdf5;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at top, #fffdf5, var(--paper));
  font:
    17px/1.4 ui-rounded,
    "Trebuchet MS",
    sans-serif;
}
button,
a,
summary {
  min-height: 44px;
  font: inherit;
}
button {
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--ink);
  background: #fffdf5;
  font-weight: 800;
  cursor: pointer;
}
button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}
.primary {
  min-height: 48px;
  background: var(--coral);
  box-shadow: 3px 3px 0 var(--ink);
}
:focus-visible {
  outline: 4px solid var(--amber);
  outline-offset: 3px;
}
.skip-link {
  position: absolute;
  left: 10px;
  top: -70px;
  z-index: 4;
  padding: 10px;
  color: var(--ink);
  background: #fff;
}
.skip-link:focus {
  top: 10px;
}
.game-bar {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px clamp(10px, 3vw, 30px);
  border-bottom: 2px solid var(--ink);
  background: #fffdf5;
}
.game-bar a {
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}
.game-bar p {
  margin: 0;
  letter-spacing: 0.08em;
  font-size: 0.82rem;
  font-weight: 900;
}
main {
  width: min(1240px, 100%);
  min-height: calc(100vh - 60px);
  margin: auto;
  padding: clamp(16px, 3vw, 34px);
}
.welcome {
  width: min(700px, 100%);
  margin: clamp(25px, 7vh, 90px) auto;
  padding: clamp(24px, 6vw, 58px);
  border: 3px solid var(--ink);
  border-radius: 28px;
  background: var(--white);
  box-shadow: 8px 8px 0 var(--amber);
  text-align: center;
}
h1,
h2,
p {
  margin-top: 0;
}
h1 {
  font-size: clamp(2.25rem, 7vw, 4.8rem);
  line-height: 0.95;
}
h2 {
  line-height: 1.05;
}
.eyebrow {
  color: #6b4430;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.1em;
}
.quiet {
  font-size: 0.94rem;
}
details {
  margin-top: 18px;
  padding: 8px;
  text-align: left;
}
summary {
  padding: 8px;
  font-weight: 900;
  cursor: pointer;
}
.route-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}
.route-head h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
}
.stamps {
  display: grid;
  grid-template-columns: repeat(5, 26px);
  gap: 4px;
}
.stamp {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 2px dashed #8ca6a5;
  border-radius: 50%;
  color: #688;
  font-size: 0.72rem;
}
.stamp.earned {
  border-style: solid;
  border-color: #8d541c;
  color: #65350f;
  background: var(--amber);
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(330px, 0.9fr);
  gap: 18px;
}
.chart-card,
.message-card,
.help {
  padding: clamp(16px, 3vw, 26px);
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--white);
}
.chart-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.north {
  align-self: start;
  padding: 7px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--amber);
  font-weight: 900;
}
.map {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--water);
}
.cell {
  position: relative;
  display: grid;
  min-height: 72px;
  place-items: center;
  border: 1px solid #397d87;
  color: #126472;
  font-size: 1.45rem;
}
.cell b {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 0.62rem;
}
.cell small {
  display: block;
  font-size: 0.55rem;
  font-weight: 900;
}
.hazard {
  color: #482f25;
  background: #dec7a2;
}
.reef {
  background: #f2b4ab;
}
.current {
  background: #bdcfeb;
}
.start,
.goal {
  outline: 3px solid var(--coral);
  outline-offset: -5px;
}
.goal {
  outline-color: #d68c22;
}
.trace {
  background: #86d8d2;
}
.boat::after {
  position: absolute;
  bottom: 3px;
  right: 4px;
  content: "⛵";
  font-size: 1rem;
}
.error {
  box-shadow: inset 0 0 0 4px #d1392f;
}
.key {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 13px;
  margin-top: 12px;
  font-size: 0.76rem;
  font-weight: 900;
}
.commands {
  min-height: 58px;
  max-height: 145px;
  overflow: auto;
  margin: 8px 0;
  padding: 9px 12px 9px 35px;
  border: 2px dashed #5c8587;
  border-radius: 12px;
  background: #eff9f7;
}
.commands .empty {
  color: #59777a;
}
.position,
.feedback {
  min-height: 1.5em;
  font-weight: 800;
}
.feedback[data-kind="error"] {
  color: #a52e24;
}
.feedback[data-kind="success"] {
  color: #176653;
}
.compass-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.compass-pad button {
  min-height: 58px;
  padding: 6px;
  font-size: 0.76rem;
}
.compass-pad b {
  display: block;
  font-size: 1.3rem;
}
.rose {
  display: grid;
  min-height: 58px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--amber);
  line-height: 1;
  font-weight: 900;
  text-align: center;
}
.route-actions,
.send-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.send-actions .primary {
  flex: 1;
}
.help {
  margin-top: 18px;
}
dialog {
  width: min(430px, calc(100% - 24px));
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--white);
  color: var(--ink);
}
dialog section {
  padding: 25px;
  text-align: center;
}
dialog::backdrop {
  background: #12364ab8;
}
.print-map {
  white-space: pre;
  padding: 14px;
  overflow: auto;
  border: 2px solid var(--ink);
  background: #b9e9e7;
  font-family: monospace;
}
@media (max-width: 760px) {
  .game-bar p {
    display: none;
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .route-head {
    display: block;
  }
  .stamps {
    margin-top: 12px;
  }
  .cell {
    min-height: 54px;
  }
}
@media (max-width: 370px) {
  main {
    padding-inline: 10px;
  }
  .chart-card,
  .message-card {
    padding: 11px;
  }
  .cell {
    min-height: 44px;
    font-size: 1rem;
  }
  .key {
    font-size: 0.65rem;
  }
  .compass-pad button {
    font-size: 0.65rem;
  }
}
@media print {
  .game-bar,
  .welcome > button,
  details > summary {
    display: none !important;
  }
  body {
    background: #fff;
  }
  .welcome {
    box-shadow: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

.game-bar {
  flex-wrap: wrap;
}
.game-bar a {
  display: inline-flex;
  align-items: center;
}
.rock {
  background-image: repeating-linear-gradient(
    135deg,
    transparent 0 7px,
    #7b583a24 7px 10px
  );
}
.current {
  background-image: repeating-linear-gradient(
    0deg,
    transparent 0 9px,
    #30496b20 9px 12px
  );
}
#chart-cells {
  font-size: 0.9rem;
}
@media (max-width: 370px) {
  .game-bar {
    gap: 6px;
    padding-inline: 10px;
  }
  .game-bar button {
    padding-inline: 10px;
  }
}

/* Keep chart and route actions in one readable desktop working area. */
.route-head h1 {
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  margin-bottom: 8px;
}
.route-head p {
  margin-bottom: 8px;
}
.chart-card,
.message-card {
  padding: 18px;
}
.chart-heading h2 {
  font-size: 1.35rem;
  margin-bottom: 8px;
}
.chart-heading p {
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.message-card h2 {
  margin-bottom: 12px;
}
.cell {
  min-height: 58px;
}
.boat::after {
  content: "";
  width: 24px;
  height: 24px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M3 26h34l-7 10H10z' fill='%23ef745c' stroke='%2312364a' stroke-width='2'/%3E%3Cpath d='M18 25V3l17 20z' fill='%23fffdf5' stroke='%2312364a' stroke-width='2'/%3E%3C/svg%3E")
    center/contain no-repeat;
}
@media (max-width: 760px) {
  .cell {
    min-height: 44px;
  }
  .chart-card,
  .message-card {
    padding: 12px;
  }
  .route-head {
    margin-bottom: 12px;
  }
  .stamps {
    display: flex;
    margin-top: 6px;
  }
}

@media (max-height: 500px) and (min-width: 600px) {
  main {
    padding: 10px;
  }
  .welcome {
    margin: 0 auto 16px;
    padding: 12px 18px;
    display: grid;
    grid-template-columns: 1fr 180px;
    gap: 8px 18px;
    text-align: left;
  }
  .welcome > .eyebrow {
    grid-column: 1 / -1;
    margin: 0;
  }
  .welcome h1 {
    font-size: 2rem;
    margin: 0;
  }
  .welcome p {
    margin-bottom: 0;
  }
  .welcome #start {
    grid-column: 2;
    grid-row: 2 / span 2;
    align-self: center;
  }
  .welcome details {
    grid-column: 1 / -1;
    margin: 0;
  }
}

#close-help {
  min-height: 48px;
}

/* Keep the map and first route choices together on a portrait phone. */
@media (max-width: 760px) {
  main {
    padding: 12px;
  }
  .route-head {
    margin-bottom: 8px;
  }
  .route-head h1 {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }
  .route-head p {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }
  .stamps {
    display: none;
  }
  .layout {
    gap: 10px;
  }
  .chart-card,
  .message-card {
    padding: 10px;
  }
  .chart-heading h2 {
    font-size: 1.1rem;
    margin-bottom: 4px;
  }
  .chart-heading p {
    font-size: 0.72rem;
    margin-bottom: 6px;
  }
  .north {
    padding: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  .cell {
    min-height: 32px;
    font-size: 0.9rem;
  }
  .cell b {
    top: 1px;
    left: 2px;
    font-size: 0.55rem;
  }
  .cell small {
    font-size: 0.47rem;
  }
  .boat::after {
    width: 18px;
    height: 18px;
    bottom: 1px;
    right: 1px;
  }
  .key {
    margin-top: 6px;
    font-size: 0.6rem;
    gap: 4px;
  }
  .chart-card details {
    margin-top: 2px;
    padding: 0;
    font-size: 0.8rem;
  }
  .chart-card summary {
    padding: 10px 0;
  }
  .message-card > .eyebrow {
    display: none;
  }
  .message-card h2 {
    font-size: 1.1rem;
    margin-bottom: 6px;
  }
  .commands {
    min-height: 44px;
    max-height: 72px;
    margin: 4px 0;
    padding: 6px 8px 6px 28px;
    font-size: 0.8rem;
  }
  .position {
    margin: 6px 0;
    font-size: 0.78rem;
  }
  .compass-pad button {
    min-height: 48px;
    font-size: 0.68rem;
    padding: 4px;
  }
  .compass-pad b {
    font-size: 1rem;
  }
  .rose {
    min-height: 48px;
  }
}
@media (max-height: 500px) and (min-width: 600px) {
  .route-head {
    margin-bottom: 8px;
  }
  .route-head h1 {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }
  .route-head p {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }
  .message-card {
    padding: 10px;
  }
  .message-card > .eyebrow {
    display: none;
  }
  .message-card h2 {
    font-size: 1.1rem;
    margin-bottom: 6px;
  }
  .commands {
    min-height: 44px;
    margin: 4px 0;
    padding-block: 6px;
    font-size: 0.8rem;
  }
  .position {
    font-size: 0.78rem;
    margin: 6px 0;
  }
  .compass-pad button {
    min-height: 48px;
    padding: 4px;
  }
}
