:root {
  color-scheme: dark;
  --ink: #f5f9ff;
  --muted: #8fb6d9;
  --navy: #03132c;
  --panel: rgba(5, 28, 61, 0.94);
  --cyan: #47dfff;
  --green: #4eff81;
  --red: #ff4d5f;
  --gold: #ffd83d;
  --orange: #ff8a16;
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #010918; }

body {
  min-height: 100svh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, rgba(23, 99, 176, .42), transparent 44%),
    linear-gradient(180deg, #020a19, #06132b 70%, #020814);
  overscroll-behavior: none;
}

button, a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.game-shell {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  position: relative;
  background:
    linear-gradient(rgba(4, 25, 54, .68), rgba(3, 15, 35, .88)),
    repeating-linear-gradient(90deg, transparent 0 51px, rgba(42, 145, 225, .06) 52px),
    #03132d;
  box-shadow: 0 0 70px rgba(0, 0, 0, .7);
  overflow: hidden;
}

.titlebar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 9px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #62cfea;
  font-size: .67rem;
  line-height: 1;
  letter-spacing: .22em;
  font-weight: 900;
}

.titlebar h1 {
  margin: 0;
  font-size: clamp(1.1rem, 4.6vw, 1.45rem);
  line-height: 1.2;
  letter-spacing: -.03em;
}

.titlebar a {
  display: inline-block;
  color: #78b8d2;
  font-size: .76rem;
  font-weight: 700;
  text-decoration: none;
}

.sound-button {
  flex: 0 0 auto;
  min-width: 66px;
  height: 43px;
  border: 1px solid rgba(87, 198, 255, .38);
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(180deg, #102d56, #071a38);
  box-shadow: inset 0 0 16px rgba(47, 151, 247, .12), 0 6px 18px rgba(0, 0, 0, .25);
  font-weight: 900;
  cursor: pointer;
}

.hud {
  display: grid;
  grid-template-columns: 1.35fr .88fr .82fr;
  gap: 7px;
  margin-bottom: 8px;
}

.hud-card {
  min-width: 0;
  min-height: 62px;
  padding: 8px 8px 6px;
  border: 2px solid rgba(78, 176, 246, .46);
  border-radius: 17px;
  background: linear-gradient(180deg, rgba(17, 51, 94, .98), rgba(5, 22, 50, .98));
  box-shadow: inset 0 0 18px rgba(27, 117, 211, .13), 0 6px 20px rgba(0, 0, 0, .24);
  text-align: center;
}

.hud-label {
  display: block;
  color: #c8ddf1;
  font-size: clamp(.68rem, 2.7vw, .82rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: .04em;
  white-space: nowrap;
}

.hud-card strong {
  display: block;
  margin-top: 4px;
  color: #fff;
  font-size: clamp(1.35rem, 6.3vw, 2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 14px rgba(255, 255, 255, .24);
  white-space: nowrap;
}

.hud-profit strong { color: var(--gold); }
.hud-profit strong span { margin-left: 2px; font-size: .56em; }
.hud-time strong { color: #ff6771; }

.chart-stage {
  height: min(55svh, 565px);
  min-height: 415px;
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(70, 168, 231, .58);
  border-radius: 21px;
  background: #041833;
  box-shadow: inset 0 0 24px rgba(25, 126, 218, .18), 0 12px 32px rgba(0, 0, 0, .28);
  isolation: isolate;
}

#chartCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.unrealized-panel {
  position: absolute;
  z-index: 4;
  top: 16px;
  right: 14px;
  min-width: 134px;
  padding: 8px 13px 10px;
  border: 1px solid rgba(108, 255, 157, .72);
  border-radius: 15px;
  color: #eafff0;
  background: linear-gradient(150deg, rgba(8, 83, 64, .92), rgba(5, 32, 48, .94));
  box-shadow: 0 0 23px rgba(52, 255, 130, .24), inset 0 0 16px rgba(72, 255, 139, .08);
  text-align: right;
  transition: border-color .2s, box-shadow .2s;
}

.unrealized-panel.negative {
  border-color: rgba(255, 87, 103, .82);
  box-shadow: 0 0 23px rgba(255, 58, 75, .2);
  background: linear-gradient(150deg, rgba(104, 22, 43, .94), rgba(34, 16, 39, .96));
}

.unrealized-panel span {
  display: block;
  color: #d2e7ee;
  font-size: .73rem;
  font-weight: 800;
}

.unrealized-panel strong {
  display: block;
  color: #85ff79;
  font-size: clamp(1.5rem, 6.4vw, 2.2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(89, 255, 96, .48);
}

.unrealized-panel.negative strong { color: #ff7582; text-shadow: 0 0 18px rgba(255, 66, 87, .42); }

.pattern-chip {
  position: absolute;
  z-index: 6;
  top: 88px;
  right: 14px;
  max-width: calc(100% - 28px);
  padding: 8px 14px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: rgba(3, 16, 37, .94);
  font-size: .86rem;
  font-weight: 900;
  box-shadow: 0 0 18px currentColor;
  animation: chip-in .35s both;
}

.pattern-chip.good { color: #6cff8d; }
.pattern-chip.bad { color: #ff6a79; }

.kappa-wrap {
  position: absolute;
  z-index: 3;
  left: 3%;
  bottom: 1.2%;
  width: min(36%, 176px);
  filter: drop-shadow(0 14px 13px rgba(0, 0, 0, .45));
  pointer-events: none;
}

.kappa-wrap img {
  width: 100%;
  display: block;
  user-select: none;
  animation: kappa-bob 1.25s ease-in-out infinite;
}

.speech-bubble {
  position: absolute;
  left: 65%;
  bottom: 78%;
  width: max-content;
  max-width: 150px;
  padding: 6px 10px;
  border: 1px solid rgba(156, 218, 255, .6);
  border-radius: 12px 12px 12px 3px;
  color: #e7f8ff;
  background: rgba(4, 26, 55, .93);
  font-size: .72rem;
  font-weight: 800;
  box-shadow: 0 5px 16px rgba(0, 0, 0, .3);
  white-space: nowrap;
}

.overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(1, 10, 26, .62);
  backdrop-filter: blur(5px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  width: min(100%, 390px);
  border: 1px solid rgba(90, 204, 255, .52);
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(13, 51, 91, .98), rgba(4, 20, 46, .99));
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 0 28px rgba(38, 139, 231, .12);
  text-align: center;
}

.start-card { padding: 24px 20px 20px; }

.mini-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  color: #071329;
  background: var(--gold);
  font-size: .75rem;
  font-weight: 900;
}

.start-card h2 {
  margin: 14px 0 9px;
  font-size: clamp(1.45rem, 6vw, 2rem);
  line-height: 1.35;
  letter-spacing: -.04em;
}

.start-card p {
  margin: 0;
  color: #c7dcef;
  font-size: .92rem;
  line-height: 1.7;
}

.start-card ul {
  width: max-content;
  max-width: 100%;
  margin: 16px auto 18px;
  padding: 0;
  list-style: none;
  color: #dbeaff;
  font-size: .83rem;
  line-height: 1.9;
  text-align: left;
}

.start-card li { white-space: nowrap; }
.start-card i { display: inline-block; width: 9px; height: 9px; margin-right: 8px; border-radius: 50%; box-shadow: 0 0 9px currentColor; }
.start-card i.good { color: var(--green); background: var(--green); }
.start-card i.bad { color: var(--red); background: var(--red); }

.start-button,
.next-button,
.share-button,
.retry-button {
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  font-weight: 900;
  cursor: pointer;
}

.start-button,
.next-button {
  width: 100%;
  color: #06233a;
  background: linear-gradient(180deg, #69f8ff, #2dbce9);
  box-shadow: 0 8px 24px rgba(49, 211, 255, .3), inset 0 2px 0 rgba(255, 255, 255, .55);
}

.result-overlay { align-items: end; background: linear-gradient(transparent 18%, rgba(1, 10, 26, .83) 62%); backdrop-filter: none; }
.result-card { padding: 18px 18px 16px; animation: result-up .35s cubic-bezier(.2,.9,.25,1.12) both; }
.result-kicker { margin: 0 0 4px; color: #75d9f5; font-size: .72rem; font-weight: 900; letter-spacing: .16em; }
.result-card h2 { margin: 0 0 12px; font-size: 1.6rem; }

.result-numbers,
.final-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-numbers div,
.final-stats div {
  padding: 9px 6px;
  border: 1px solid rgba(82, 174, 231, .27);
  border-radius: 14px;
  background: rgba(2, 17, 40, .62);
}

.result-numbers span,
.final-stats span { display: block; color: #9cb8d2; font-size: .72rem; font-weight: 800; }
.result-numbers strong,
.final-stats strong { display: block; margin-top: 2px; color: #7fff87; font-size: 1.24rem; font-variant-numeric: tabular-nums; }
.result-lesson { min-height: 42px; margin: 10px 0 12px; color: #d5e4ef; font-size: .83rem; line-height: 1.55; }

.final-overlay { background: rgba(1, 9, 23, .82); }
.final-card { padding: 18px; }
.rank-badge {
  width: 68px;
  height: 68px;
  margin: 6px auto;
  display: grid;
  place-items: center;
  border: 3px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  background: #123157;
  box-shadow: 0 0 24px rgba(255, 215, 52, .42), inset 0 0 16px rgba(255, 211, 47, .17);
  font-size: 2.5rem;
  font-weight: 1000;
}

.final-card h2 { margin: 5px 0 10px; font-size: 1.45rem; }
.final-total { margin-bottom: 10px; padding: 10px; border-radius: 16px; background: linear-gradient(135deg, rgba(20, 108, 77, .82), rgba(5, 42, 53, .88)); }
.final-total span { display: block; color: #d4f4e1; font-size: .76rem; font-weight: 800; }
.final-total strong { display: block; color: #83ff7a; font-size: 2rem; line-height: 1.1; text-shadow: 0 0 14px rgba(91, 255, 109, .42); }
.final-comment { margin: 11px 4px 13px; color: #d8e8f3; font-size: .86rem; line-height: 1.55; }
.final-actions { display: grid; grid-template-columns: 1.35fr 1fr; gap: 8px; }
.share-button { color: #06101e; background: #fff; }
.retry-button { color: #dff7ff; border: 1px solid rgba(94, 201, 255, .42); background: #0d3158; }

.greed-panel {
  padding: 9px 8px 8px;
}

.greed-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
  color: #d8e7f3;
  font-size: .78rem;
  font-weight: 900;
}

.greed-heading b { color: #61ff83; font-size: .74rem; }

.greed-track {
  height: 24px;
  position: relative;
  overflow: hidden;
  border: 3px solid #d7e6f1;
  border-radius: 999px;
  background: #06152d;
  box-shadow: 0 0 0 3px #153a63, 0 6px 18px rgba(0, 0, 0, .35);
}

.greed-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #0be564 0 20%, #aff400 35%, #ffe000 57%, #ff8a00 77%, #f32d42 100%);
}

.greed-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 2px), rgba(255, 255, 255, .34) calc(20% - 2px) 20%);
}

.greed-needle {
  position: absolute;
  z-index: 2;
  top: -3px;
  bottom: -3px;
  left: 0;
  width: 7px;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 0 10px rgba(255,255,255,.95), 0 0 18px rgba(255, 78, 60, .8);
  transform: translateX(-50%);
  transition: left .35s ease;
}

.take-profit-button {
  width: 100%;
  min-height: 84px;
  position: relative;
  overflow: hidden;
  border: 3px solid #fff3a4;
  border-radius: 24px;
  color: #5c2800;
  background: linear-gradient(180deg, #fff96a 0%, #ffdb18 45%, #f19a00 100%);
  box-shadow: 0 0 0 4px #a86200, 0 10px 28px rgba(255, 173, 0, .4), inset 0 5px 5px rgba(255, 255, 255, .7), inset 0 -7px 10px rgba(154, 76, 0, .25);
  cursor: pointer;
  transform: translateZ(0);
}

.take-profit-button::after {
  content: "";
  position: absolute;
  top: -70%;
  left: -38%;
  width: 34%;
  height: 240%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.9), transparent);
  transform: rotate(24deg);
  animation: button-shine 2.3s infinite;
}

.take-profit-button span { display: block; margin-bottom: -4px; font-size: .72rem; font-weight: 900; letter-spacing: .08em; }
.take-profit-button strong { display: block; font-size: clamp(2rem, 9vw, 3rem); line-height: 1; letter-spacing: .02em; }
.take-profit-button:active:not(:disabled) { transform: translateY(3px) scale(.992); box-shadow: 0 0 0 4px #8d5100, 0 4px 13px rgba(255, 173, 0, .34), inset 0 4px 7px rgba(117, 56, 0, .24); }
.take-profit-button:disabled { filter: saturate(.3) brightness(.62); cursor: not-allowed; box-shadow: 0 0 0 3px #445166; }

.game-note {
  margin: 11px 8px 0;
  color: #6f8eaa;
  font-size: .64rem;
  line-height: 1.45;
  text-align: center;
}

.danger-pulse { animation: danger-pulse .48s infinite alternate; }
.screen-flash { animation: screen-flash .42s both; }

@keyframes kappa-bob { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-4px) rotate(1deg); } }
@keyframes chip-in { from { opacity: 0; transform: translateY(-8px) scale(.95); } }
@keyframes result-up { from { opacity: 0; transform: translateY(28px); } }
@keyframes button-shine { 0%,55% { left: -38%; } 90%,100% { left: 120%; } }
@keyframes danger-pulse { to { box-shadow: 0 0 0 3px #ff4e58, 0 0 28px rgba(255, 36, 62, .7); } }
@keyframes screen-flash { 50% { filter: brightness(1.35); } }

@media (max-width: 390px) {
  .game-shell { padding-left: 8px; padding-right: 8px; }
  .titlebar { min-height: 60px; }
  .titlebar a { font-size: .68rem; }
  .sound-button { min-width: 58px; height: 40px; font-size: .84rem; }
  .hud { gap: 5px; }
  .hud-card { min-height: 56px; padding: 7px 5px 5px; border-radius: 14px; }
  .chart-stage { min-height: 390px; height: 52svh; }
  .unrealized-panel { top: 11px; right: 10px; min-width: 118px; padding: 7px 10px 8px; }
  .take-profit-button { min-height: 74px; border-radius: 20px; }
  .game-note { font-size: .58rem; }
}

@media (max-height: 710px) {
  .titlebar { min-height: 54px; }
  .eyebrow, .titlebar a { display: none; }
  .chart-stage { min-height: 350px; height: 49svh; }
  .take-profit-button { min-height: 68px; }
  .greed-panel { padding-top: 7px; padding-bottom: 7px; }
  .game-note { display: none; }
}

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