*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --font-ui: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --font-round: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --ink: #183552;
  --ink-soft: #587089;
  --accent: #1f8fd6;
  --warm: #d4561c;
  --bg: #1b6aa5;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

p,
h1 {
  margin: 0;
}

button {
  font: inherit;
}

/* Keep the home link apart from the tank and other controls. */
.home-link {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--safe-left) + 12px);
  z-index: 18;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(24, 53, 82, 0.15);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: #2b4c6b;
  box-shadow: 0 3px 10px rgba(10, 40, 70, 0.16);
  text-decoration: none;
  touch-action: manipulation;
}

.home-link svg {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.home-link:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tank {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Title and fish count, between the round buttons at the top. */
.tank-head {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 232px);
  text-align: center;
  color: #17507e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  pointer-events: none;
}

.tank-title {
  font-family: var(--font-round);
  font-size: 19px;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
}

.tank-count {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 800;
}

.toast {
  position: absolute;
  top: calc(var(--safe-top) + 76px);
  left: 50%;
  z-index: 8;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 6px 18px rgba(10, 40, 70, 0.2);
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tank-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 18px);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 28px;
  border: 0;
  border-radius: 999px;
  background: #ffd84d;
  color: #5a3b00;
  font-family: var(--font-round);
  font-size: 19px;
  font-weight: 900;
  box-shadow: 0 5px 0 #d9a300, 0 10px 24px rgba(10, 40, 70, 0.25);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.cta svg {
  width: 24px;
  height: 24px;
}

.cta:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #d9a300, 0 6px 16px rgba(10, 40, 70, 0.25);
}

.cta:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

/* Night: a round button beside the home link. */
.night-toggle {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--safe-left) + 64px);
  z-index: 18;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 84, 134, 0.78);
  color: #fff6c4;
  cursor: pointer;
  touch-action: manipulation;
}

.night-toggle svg {
  width: 24px;
  height: 24px;
}

.night-toggle .icon-sun,
.night-toggle[aria-pressed="true"] .icon-moon {
  display: none;
}

.night-toggle[aria-pressed="true"] .icon-sun {
  display: block;
}

/* Treasure book: a round button on the other side of the draw button. */
.book-button {
  position: absolute;
  left: calc(var(--safe-left) + 16px);
  bottom: 4px;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #5a3b00;
  box-shadow: 0 4px 12px rgba(10, 40, 70, 0.2);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.book-button svg {
  width: 28px;
  height: 28px;
}

.book-button:active {
  transform: translateY(2px);
}

.book-count {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 900;
  text-align: center;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.book-cell {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 14px;
  background: #fff6df;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
}

.book-cell canvas {
  width: 56px;
  height: 56px;
}

.book-cell.is-missing {
  background: #edf2f6;
  color: var(--ink-soft);
}

.book-hint {
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
}

/* Photo: a round button beside the draw button. */
.photo-button {
  position: absolute;
  right: calc(var(--safe-right) + 16px);
  bottom: 4px;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #2b4c6b;
  box-shadow: 0 4px 12px rgba(10, 40, 70, 0.2);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.photo-button svg {
  width: 26px;
  height: 26px;
}

.photo-button:active {
  transform: translateY(2px);
}

/* Drawing sheet */
.draw-sheet {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
  background: rgba(8, 36, 64, 0.5);
}

.draw-sheet[hidden] {
  display: none;
}

.draw-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 460px);
  max-height: 100%;
  overflow-y: auto;
  padding: 16px 14px 14px;
  border-radius: 24px;
  background: #f4f9fc;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  touch-action: pan-y;
}

.draw-title {
  font-family: var(--font-round);
  font-size: 21px;
  font-weight: 900;
}

.draw-sub {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.paper-wrap {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin-top: 10px;
  border: 2px solid #d5e4ee;
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.paper,
.paper-top {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.paper-top {
  touch-action: none;
  cursor: crosshair;
}

.is-eye .paper-top {
  cursor: pointer;
}

.draw-msg {
  min-height: 1.5em;
  margin-top: 6px;
  color: var(--warm);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.kind-picker {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.kind {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 4px 12px 4px 8px;
  border: 2px solid #d5e4ee;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-round);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.kind svg {
  width: 32px;
  height: 24px;
}

.kind[aria-pressed="true"] {
  border-color: #1f8fd6;
  background: #e4f3fc;
  color: #0d5c95;
}

.is-eye .kind-picker {
  display: none;
}

.draw-tools {
  width: 100%;
}

.is-eye .draw-tools {
  display: none;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  justify-items: center;
}

.swatch {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px rgba(24, 53, 82, 0.22);
  cursor: pointer;
  touch-action: manipulation;
}

.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 3px var(--ink);
  transform: scale(1.06);
}

.swatch:focus-visible,
.tool:focus-visible,
.size:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  margin-top: 10px;
}

.tool-group {
  display: flex;
  gap: 4px;
}

.tool,
.size {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 48px;
  padding: 2px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.tool svg {
  width: 24px;
  height: 24px;
}

.tool span {
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.size i {
  display: block;
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background: currentColor;
}

.tool[aria-pressed="true"],
.size[aria-pressed="true"] {
  background: #dcecf7;
  color: #0d5c95;
}

.tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.draw-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.btn {
  min-height: 48px;
  padding: 12px 22px;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-round);
  font-size: 17px;
  font-weight: 900;
  line-height: 1.3;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(2px);
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.btn-gold {
  background: #ffd84d;
  color: #5a3b00;
  box-shadow: 0 4px 0 #d9a300;
}

.btn-sub {
  background: #dfe9f0;
  color: var(--ink);
}

/* How to play */
.help-toggle {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 64px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 84, 134, 0.78);
  color: #fff;
  font-family: var(--font-round);
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
}

.help-toggle:focus-visible,
.sound-toggle:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.help-sheet {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: rgba(8, 36, 64, 0.55);
}

.help-sheet[hidden] {
  display: none;
}

.help-panel {
  width: min(100%, 360px);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 18px 16px;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  touch-action: pan-y;
}

.help-title {
  font-family: var(--font-round);
  font-size: 21px;
  font-weight: 900;
  text-align: center;
}

.help-steps {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.help-steps li {
  position: relative;
  margin-top: 10px;
  padding-left: 34px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.6;
  counter-increment: step;
}

.help-steps li::before {
  content: counter(step);
  position: absolute;
  top: 1px;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-round);
  font-size: 14px;
  font-weight: 900;
  line-height: 24px;
  text-align: center;
}

.help-steps strong {
  color: var(--warm);
}

.help-close {
  display: block;
  margin: 16px auto 0;
  padding: 10px 34px;
  border: 0;
  border-radius: 999px;
  background: #ffd84d;
  color: #5a3b00;
  font-family: var(--font-round);
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 4px 0 #d9a300;
  cursor: pointer;
}

.help-close:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* Setting a creature free */
.release-panel {
  text-align: center;
}

.release-preview {
  display: block;
  width: 150px;
  height: 150px;
  margin: 10px auto 0;
  border-radius: 18px;
  background: linear-gradient(180deg, #8fd6f2, #3fa6dc);
}

.release-note {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
}

.release-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

/* Sound and vibration toggle */
.sound-toggle {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 12px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 84, 134, 0.78);
  color: #fff;
  cursor: pointer;
}

.sound-toggle svg {
  width: 24px;
  height: 24px;
}

.sound-toggle .icon-off,
.sound-toggle[aria-pressed="false"] .icon-on {
  display: none;
}

.sound-toggle[aria-pressed="false"] .icon-off {
  display: block;
}

@media (max-height: 640px) {
  .draw-panel {
    padding: 10px 12px;
  }

  .paper-wrap {
    width: min(100%, 360px);
  }

  .swatch {
    width: 34px;
    height: 34px;
  }
}

/* Wide and short screens (phones held sideways): paper on the left, tools on the right. */
@media (orientation: landscape) and (max-height: 520px) {
  .draw-panel {
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr);
    grid-template-areas:
      "title title"
      "paper tools"
      "paper msg"
      "paper actions";
    column-gap: 14px;
    width: min(100%, 760px);
  }

  .draw-title,
  .draw-sub {
    grid-area: title;
  }

  .draw-sub {
    display: none;
  }

  .paper-wrap {
    grid-area: paper;
    width: auto;
    height: min(62vh, 260px);
  }

  .draw-msg {
    grid-area: msg;
  }

  .draw-tools {
    grid-area: tools;
  }

  .draw-actions {
    grid-area: actions;
    justify-content: center;
  }
}

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

/* Focus outlines are turned off across the site. */
*:focus,
*:focus-visible,
*:focus-within {
  outline: none !important;
}
