:root {
  color-scheme: light;
  --ink: #123548;
  --muted: #4c7181;
  --surface: rgba(255,255,255,.95);
  --primary: #ff8b3d;
  --primary-dark: #df6518;
  --secondary: #e4f6fb;
  --shadow: 0 18px 55px rgba(9, 69, 91, .22);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-rounded, "Arial Rounded MT Bold", Nunito, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.75), transparent 24rem),
    linear-gradient(145deg, #d9f8ff 0%, #7bd4ed 48%, #46b4d6 100%);
  overflow-x: hidden;
}

button { font: inherit; }
button:focus-visible { outline: 4px solid #ffe16b; outline-offset: 3px; }

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #116b87;
  font-size: .74rem;
  font-weight: 900;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; line-height: 1; }
h1 { font-size: clamp(1.75rem, 4vw, 2.7rem); }
h2 { font-size: clamp(1.65rem, 4vw, 2.3rem); }

.topbar-actions { display: flex; gap: 9px; }

.icon-button, .close-button {
  border: 0;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255,255,255,.9);
  box-shadow: 0 7px 20px rgba(9, 69, 91, .16);
}

.icon-button {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  font-size: 1.25rem;
}

.game-card {
  position: relative;
  height: min(74vh, 760px);
  min-height: 520px;
  border: 5px solid rgba(255,255,255,.86);
  border-radius: 30px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #5ec9e8;
}

#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; }

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.hud-pill, .shark-warning {
  padding: 9px 13px;
  border-radius: 999px;
  font-weight: 900;
  box-shadow: 0 7px 24px rgba(9, 69, 91, .18);
  backdrop-filter: blur(8px);
}

.hud-pill { background: rgba(255,255,255,.88); }
.shark-warning {
  margin-left: auto;
  color: white;
  background: #d94242;
  animation: pulse .7s infinite alternate;
}

.message-bubble {
  position: absolute;
  left: 50%;
  bottom: 94px;
  transform: translateX(-50%);
  max-width: min(80%, 500px);
  padding: 11px 17px;
  border-radius: 18px;
  background: rgba(255,255,255,.91);
  box-shadow: 0 8px 25px rgba(9, 69, 91, .2);
  font-weight: 900;
  text-align: center;
  opacity: 1;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}

.message-bubble.hide { opacity: 0; transform: translate(-50%, 8px); }

.make-fish-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px 22px;
  border: 0;
  border-radius: 20px;
  color: white;
  background: linear-gradient(180deg, #ff9d56, #f4782c);
  box-shadow: 0 10px 0 #c65416, 0 17px 30px rgba(103, 49, 11, .25);
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
}

.make-fish-button:active { transform: translateY(6px); box-shadow: 0 4px 0 #c65416, 0 10px 20px rgba(103,49,11,.2); }
.make-fish-icon { font-size: 1.45rem; }

.creator-dialog, .confirm-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 24px);
}

.creator-dialog::backdrop, .confirm-dialog::backdrop {
  background: rgba(2, 38, 54, .62);
  backdrop-filter: blur(5px);
}

.creator-card {
  width: min(620px, calc(100vw - 24px));
  max-height: min(92vh, 820px);
  overflow: auto;
  padding: 22px;
  border-radius: 28px;
  background: #f7fdff;
  box-shadow: var(--shadow);
}

.creator-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.close-button { width: 46px; height: 46px; border-radius: 15px; font-size: 1.8rem; line-height: 1; }

.preview-wrap {
  margin: 18px 0 14px;
  border: 3px solid #ccecf6;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(#8adcf1, #5fc8e5);
}
#preview-canvas { width: 100%; height: 150px; display: block; }

fieldset { margin: 18px 0 0; padding: 0; border: 0; }
legend { margin-bottom: 10px; font-size: 1rem; font-weight: 900; }
.choice-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.choice-button, .pattern-button, .swatch-button {
  border: 3px solid transparent;
  cursor: pointer;
  background: white;
  box-shadow: 0 5px 13px rgba(9, 69, 91, .1);
}

.choice-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 60px;
  border-radius: 17px;
  font-weight: 900;
}

.choice-button.selected, .pattern-button.selected, .swatch-button.selected {
  border-color: #165f7a;
  box-shadow: 0 0 0 4px #c7f3ff;
}

.mini-fish { display: inline-block; }
.small-fish { font-size: 1.3rem; }
.large-fish { font-size: 2rem; }

.swatch-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatch-button { aspect-ratio: 1; border-radius: 50%; min-width: 42px; }
.pattern-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.pattern-button {
  min-height: 68px;
  border-radius: 16px;
  font-size: .87rem;
  font-weight: 900;
  color: var(--ink);
  background-color: white;
  background-size: 18px 18px;
}

.creator-actions, .confirm-actions { display: flex; gap: 12px; margin-top: 24px; }
.primary-button, .secondary-button, .danger-button {
  flex: 1;
  min-height: 56px;
  padding: 10px 16px;
  border-radius: 17px;
  font-weight: 900;
  cursor: pointer;
}
.primary-button { border: 0; color: white; background: #168ec0; box-shadow: 0 7px 0 #0b6488; }
.secondary-button { border: 3px solid #b7e4f2; color: var(--ink); background: #ecfaff; }
.danger-button { border: 0; color: white; background: #d94b4b; }

.confirm-card {
  width: min(430px, calc(100vw - 24px));
  padding: 28px;
  border-radius: 28px;
  background: white;
  text-align: center;
  box-shadow: var(--shadow);
}
.confirm-icon { font-size: 3.2rem; margin-bottom: 10px; }
.confirm-card p { color: var(--muted); }

@keyframes pulse { from { transform: scale(.97); } to { transform: scale(1.04); } }

@media (max-width: 680px) {
  .app-shell { padding-left: 8px; padding-right: 8px; }
  .topbar { padding: 0 5px; }
  .icon-button { width: 44px; height: 44px; border-radius: 14px; }
  .game-card { height: calc(100vh - 100px); min-height: 540px; border-width: 3px; border-radius: 24px; }
  .make-fish-button { left: 50%; right: auto; transform: translateX(-50%); width: max-content; }
  .make-fish-button:active { transform: translate(-50%, 6px); }
  .message-bubble { bottom: 98px; }
  .swatch-grid { grid-template-columns: repeat(4, 1fr); }
  .pattern-grid { grid-template-columns: repeat(2, 1fr); }
  .creator-actions, .confirm-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behaviour: auto !important; }
}
