:root {
  --ink: #fff8e7;
  --panel: #103c43;
  --line: #4ca6a1;
  --gold: #e0ba62;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #07313c;
  color: var(--ink);
  font-family: 'Noto Sans KR', 'Source Sans 3', 'Apple SD Gothic Neo', 'Malgun Gothic', Arial, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

body {
  background:
    radial-gradient(circle at 50% -10%, #2c9c9a 0%, #11616a 32%, #123f46 58%, #062630 100%),
    repeating-linear-gradient(
      135deg,
      rgba(235, 210, 151, 0.06) 0 2px,
      transparent 2px 10px
    );
}

.shell {
  min-height: 100svh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
}

.topline {
  width: min(100%, 980px);
  display: flex;
  justify-content: space-between;
  align-items: end;
}

.brand {
  font-family: 'Noto Serif KR', 'Cinzel', 'AppleMyungjo', serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 2px 0 #15393c, 0 0 18px rgba(224, 186, 98, 0.3);
}

.subtitle {
  font-size: 12px;
  opacity: 0.82;
}

.github {
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  border-radius: 6px;
  padding: 7px 10px;
  text-decoration: none;
  font-size: 12px;
}

#game {
  width: min(
    1280px,
    calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 16px),
    calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 62px) * 16 / 9)
  );
  aspect-ratio: 16 / 9;
  max-height: none;
  border: 2px solid #4ca6a1;
  border-radius: 12px;
  overflow: hidden;
  background: #0b4250;
  box-shadow:
    0 0 0 1px rgba(235, 210, 151, 0.34),
    0 18px 48px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 240, 180, 0.08);
}

#game canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Landscape phones / short screens */
@media (max-height: 540px) {
  .topline {
    display: none;
  }

  #game {
    width: min(
      calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9)
    );
    height: auto;
    max-height: none;
    max-width: 100%;
  }

  .shell {
    gap: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
      env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
}

/* Wide tablets / desktop landscape */
@media (min-width: 900px) and (min-height: 700px) {
  .brand {
    font-size: 28px;
  }

  .subtitle {
    font-size: 14px;
  }
}

/* Narrow screens keep the 16:9 playfield edge-to-edge. */
@media (max-width: 420px) {
  #game {
    width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .shell {
    gap: 4px;
    padding-left: 0;
    padding-right: 0;
  }

  .topline {
    padding: 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Aegean desktop chrome */
@media (min-width: 900px) {
  body {
    background:
      radial-gradient(ellipse at 50% 44%, rgba(44, 156, 154, 0.54) 0%, rgba(17, 97, 106, 0.78) 43%, rgba(5, 34, 43, 0.98) 100%),
      repeating-linear-gradient(112deg, rgba(235, 210, 151, 0.05) 0 1px, transparent 1px 13px),
      repeating-linear-gradient(73deg, rgba(106, 125, 69, 0.07) 0 2px, transparent 2px 28px),
      #062630;
  }

  .shell {
    position: relative;
    isolation: isolate;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .shell > * {
    position: relative;
    z-index: 1;
  }

  #game {
    position: relative;
    width: min(
      1280px,
      calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 16px),
      calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 108px) * 16 / 9)
    );
    aspect-ratio: 16 / 9;
    max-height: none;
    padding: 0;
    border: 4px solid #e0ba62;
    border-radius: 18px;
    background:
      radial-gradient(ellipse at center, rgba(255, 244, 184, 0.2) 0%, transparent 68%),
      linear-gradient(135deg, #74613c 0%, #e0c983 11%, #ad9560 20%, #d7bd75 82%, #1f7778 100%);
    box-shadow:
      inset 0 0 0 2px rgba(255, 239, 156, 0.82),
      inset 0 0 0 6px rgba(16, 60, 67, 0.82),
      inset 0 0 24px 9px rgba(6, 38, 48, 0.68),
      0 0 0 1px rgba(224, 186, 98, 0.4),
      0 18px 28px rgba(0, 0, 0, 0.7),
      0 34px 70px rgba(0, 0, 0, 0.52);
  }

  #game::before {
    position: absolute;
    inset: 4px;
    z-index: 2;
    border-radius: 10px;
    box-shadow:
      inset 20px 0 26px -22px rgba(5, 8, 4, 0.82),
      inset -20px 0 26px -22px rgba(5, 8, 4, 0.82),
      inset 0 20px 26px -22px rgba(5, 8, 4, 0.86),
      inset 0 -20px 26px -22px rgba(5, 8, 4, 0.86);
    content: '';
    pointer-events: none;
  }

  #game canvas {
    position: relative;
    z-index: 1;
    border: 1px solid rgba(76, 166, 161, 0.9);
    box-shadow: 0 0 0 1px rgba(224, 186, 98, 0.34), inset 0 0 22px rgba(5, 34, 43, 0.42);
  }
}

@media (min-width: 1200px) {
  .shell::before,
  .shell::after {
    position: absolute;
    top: 50%;
    z-index: 0;
    width: min(280px, calc((100vw - 640px) / 2));
    height: min(760px, calc(100svh - 120px));
    border: 1px solid rgba(216, 181, 72, 0.28);
    border-top: 5px solid rgba(216, 181, 72, 0.4);
    border-bottom: 5px solid rgba(216, 181, 72, 0.4);
    background:
      radial-gradient(circle at 8% 3%, transparent 0 9px, rgba(216, 181, 72, 0.38) 10px 11px, transparent 12px),
      radial-gradient(circle at 92% 97%, transparent 0 9px, rgba(216, 181, 72, 0.3) 10px 11px, transparent 12px),
      linear-gradient(90deg, transparent 0 17%, rgba(45, 85, 53, 0.7) 17% 19%, transparent 19% 47%, rgba(216, 181, 72, 0.45) 47% 49%, transparent 49% 81%, rgba(45, 85, 53, 0.62) 81% 83%, transparent 83%),
      linear-gradient(180deg, rgba(45, 85, 53, 0.4), rgba(18, 32, 20, 0.08) 18%, rgba(18, 32, 20, 0.08) 82%, rgba(45, 85, 53, 0.4));
    box-shadow: inset 0 0 32px rgba(4, 8, 5, 0.62), 0 0 34px rgba(0, 0, 0, 0.28);
    content: '';
    opacity: 0.62;
    pointer-events: none;
    transform: translateY(-50%);
  }

  .shell::before {
    left: 24px;
    border-left: 5px double rgba(216, 181, 72, 0.42);
    border-radius: 16px 3px 3px 16px;
  }

  .shell::after {
    right: 24px;
    border-right: 5px double rgba(216, 181, 72, 0.42);
    border-radius: 3px 16px 16px 3px;
  }
}
