:root {
  --bg: #0f1c1a;
  --bg-elevated: #162824;
  --ink: #e8f2ef;
  --muted: #8aa89f;
  --accent: #3dd6c3;
  --accent-deep: #1fa892;
  --warn: #f0a35e;
  --line: rgba(232, 242, 239, 0.08);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "Sora", sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(61, 214, 195, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 20%, rgba(240, 163, 94, 0.12), transparent 50%),
    linear-gradient(165deg, #0c1614 0%, var(--bg) 45%, #13221f 100%);
  line-height: 1.6;
}

.bg-glow {
  position: fixed;
  inset: auto -20% -30% auto;
  width: 55vw;
  height: 55vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(61, 214, 195, 0.08), transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: drift 14s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-8%, -6%) scale(1.08); }
}

.site-header,
main,
.site-footer {
  position: relative;
  z-index: 1;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  gap: 1.25rem;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.2s ease;
}

.nav a:hover {
  color: var(--accent);
}

.hero {
  max-width: 960px;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 5rem;
  min-height: calc(100vh - 5rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hero-brand {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 8vw, 5rem);
  line-height: 1;
  color: var(--accent);
  animation: rise 0.7s ease both;
}

.hero-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 400;
  font-style: italic;
  max-width: 14ch;
  animation: rise 0.7s ease 0.08s both;
}

.hero-desc {
  margin: 0 0 2rem;
  max-width: 36ch;
  color: var(--muted);
  font-size: 1.05rem;
  animation: rise 0.7s ease 0.16s both;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  animation: rise 0.7s ease 0.24s both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 1.4rem;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #06211d;
}

.btn-primary:hover {
  background: #55e0cf;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.about,
.calculator-section {
  max-width: 960px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

.about h2,
.calculator-section h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 400;
}

.about p,
.section-desc {
  margin: 0;
  max-width: 42ch;
  color: var(--muted);
}

.calculator-section {
  padding-bottom: 5rem;
}

.calculator {
  margin-top: 2rem;
  width: min(100%, 340px);
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 0.6s ease both;
}

.display {
  margin-bottom: 1rem;
  padding: 1.1rem 1rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  text-align: right;
  min-height: 5.2rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.25rem;
}

.expression {
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
}

.result {
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  word-break: break-all;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
}

.key {
  appearance: none;
  border: none;
  border-radius: 14px;
  min-height: 3.35rem;
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  background: rgba(232, 242, 239, 0.06);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.key:hover {
  background: rgba(232, 242, 239, 0.12);
}

.key:active {
  transform: scale(0.96);
}

.key-fn {
  color: var(--warn);
  background: rgba(240, 163, 94, 0.1);
}

.key-fn:hover {
  background: rgba(240, 163, 94, 0.18);
}

.key-op {
  color: var(--accent);
  background: rgba(61, 214, 195, 0.1);
}

.key-op:hover,
.key-op.is-active {
  background: rgba(61, 214, 195, 0.22);
}

.key-eq {
  background: var(--accent-deep);
  color: #041512;
}

.key-eq:hover {
  background: var(--accent);
}

.key-zero {
  grid-column: span 2;
}

.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

/* Mini-game dock (bottom-right) */
.games-dock {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0.55rem;
  font-family: var(--font-body);
}

.contra-widget,
.tetris-widget {
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 0.55rem;
}

.game-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.95rem;
  border: 1px solid rgba(61, 214, 195, 0.35);
  border-radius: 999px;
  background: rgba(22, 40, 36, 0.92);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.game-toggle:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: rgba(26, 52, 46, 0.96);
}

.game-toggle-icon {
  color: var(--accent);
  font-size: 0.7rem;
}

.game-panel {
  display: none;
  padding: 0.55rem;
  border-radius: 16px;
  background: rgba(12, 22, 20, 0.96);
  border: 1px solid rgba(61, 214, 195, 0.22);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  animation: game-pop 0.22s ease both;
}

.game-panel.is-open {
  display: block;
}

.contra-panel {
  width: min(calc(100vw - 2rem), 336px);
}

.tetris-panel {
  width: min(calc(100vw - 2rem), 220px);
}

@keyframes game-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.game-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  padding: 0 0.15rem;
}

.game-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.game-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}

.game-close:hover {
  color: var(--ink);
  background: rgba(232, 242, 239, 0.08);
}

#contra-canvas,
#tetris-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #0a1810;
  image-rendering: pixelated;
  outline: none;
}

.game-hint {
  margin: 0.45rem 0 0.1rem;
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

@media (max-width: 560px) {
  .hero {
    padding-top: 3rem;
    min-height: auto;
  }

  .nav {
    gap: 0.85rem;
  }

  .calculator {
    width: 100%;
  }

  .games-dock {
    right: 0.65rem;
    bottom: 0.65rem;
  }
}
