/* ===== Global Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

:root {
  --calc-bg: #dce6f5;
  --calc-nav-bg: #bdd0ec;
  --calc-body-bg: #2d3748;
  --calc-display-bg: #c8d6c5;
  --calc-btn-num: #3a4a5c;
  --calc-btn-op: #e67e22;
  --calc-btn-clear: #e74c3c;
  --calc-text: #333333;

  --game-bg: #0f0f1a;
  --game-card-bg: #1a1a2e;
  --game-card-hover: #16213e;
  --game-accent: #e94560;
  --game-text: #e0e0e0;
  --game-sidebar-bg: #1a1a2e;

  --radius: 8px;
  --transition: 0.2s ease;
}

/* ===== Calculator View ===== */
#view-calculator {
  background: var(--calc-bg);
  min-height: 100vh;
}

.calc-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--calc-nav-bg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-img {
  height: 40px;
  width: auto;
  display: block;
}

.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--calc-text);
}

.logo-highlight { color: #2563eb; }

.logo-tagline {
  font-size: 0.7rem;
  font-weight: 500;
  color: #555;
  margin-top: 2px;
}

.nav-links {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--calc-text);
  text-decoration: none;
  font-weight: 500;
}

.nav-links a:hover { text-decoration: underline; }

.calc-main {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
}

.calc-main h1 {
  font-size: 1.75rem;
  color: var(--calc-text);
  margin-bottom: 8px;
}

.calc-subtitle {
  color: #555;
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.calculator-container {
  background: var(--calc-body-bg);
  border-radius: 16px;
  padding: 20px;
  max-width: 360px;
  margin: 0 auto 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.mini-calc {
  max-width: 280px;
  margin: 20px auto;
}

.mini-calc .calc-grid {
  grid-template-columns: repeat(4, 1fr);
}

.mini-calc .btn-num,
.mini-calc .btn-op,
.mini-calc .btn-clear,
.mini-calc .btn-eq {
  padding: 12px;
  font-size: 1rem;
}

.calc-hint {
  text-align: center;
  font-size: 0.85rem;
  color: #666;
  margin: -8px 0 24px;
  font-style: italic;
}

.calc-mode-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}

.mode-btn {
  flex: 1;
  padding: 6px 12px;
  font-size: 12px;
  background: #4a5568;
  color: rgba(255,255,255,0.8);
  border: 1px solid #5a6578;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.mode-btn:hover {
  background: #5a6578;
  color: white;
}

.mode-btn.active {
  background: #e67e22;
  color: white;
  border-color: #e67e22;
}

/* Why Choose Cards */
.why-choose-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.why-card {
  background: rgba(255,255,255,0.6);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid rgba(0,0,0,0.06);
}

.why-card h3 {
  font-size: 1rem;
  margin: 0 0 8px;
  color: #1a1a1a;
}

.why-card p {
  font-size: 0.9rem;
  margin: 0;
  line-height: 1.5;
  color: #444;
}

.calc-display {
  background: var(--calc-display-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  min-height: 80px;
  text-align: right;
  overflow-x: auto;
}

.calc-expression {
  font-size: 1rem;
  color: #555;
  min-height: 24px;
  word-break: break-all;
}

.calc-result {
  font-size: 2rem;
  font-weight: 700;
  color: #1a1a1a;
}

.calc-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.sci-row { flex-wrap: wrap; }

.btn-sci {
  flex: 1;
  min-width: 40px;
  padding: 10px;
  font-size: 0.9rem;
  background: #4a5568;
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.btn-sci:hover { filter: brightness(1.2); }

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

.btn-num, .btn-op, .btn-clear, .btn-eq {
  padding: 16px;
  font-size: 1.2rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.btn-num { background: var(--calc-btn-num); color: white; }
.btn-op { background: var(--calc-btn-op); color: white; }
.btn-clear { background: var(--calc-btn-clear); color: white; }
.btn-eq { background: var(--calc-btn-op); color: white; grid-row: span 2; }
.btn-zero { grid-column: span 2; }

.btn-num:hover, .btn-op:hover, .btn-sci:hover { filter: brightness(1.2); transform: translateY(-1px); }
.btn-clear:hover, .btn-eq:hover { filter: brightness(1.1); }

/* SEO Content */
.seo-content {
  color: var(--calc-text);
  line-height: 1.7;
}

.seo-content h2 {
  font-size: 1.25rem;
  margin: 28px 0 12px;
  color: #1a1a1a;
}

.seo-content h3 {
  font-size: 1.1rem;
  margin: 20px 0 8px;
  color: #333;
}

.seo-content p {
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.seo-content a { color: #2563eb; }
.seo-content a:hover { text-decoration: underline; }

.calc-footer {
  text-align: center;
  padding: 24px;
  color: #666;
  font-size: 0.9rem;
}

/* ===== Games View (hidden until 0000 entered) ===== */
#view-games[hidden],
#view-play[hidden] {
  display: none !important;
  visibility: hidden !important;
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0);
  pointer-events: none;
}

#view-games {
  background: var(--game-bg);
  min-height: 100vh;
  color: var(--game-text);
}

.games-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: var(--game-bg);
  z-index: 10;
}

.search-input {
  background: var(--game-card-bg);
  border: 1px solid #2a2a4a;
  color: white;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 14px;
  width: 240px;
  outline: none;
}

.search-input::placeholder { color: #888; }

.btn-exit {
  background: var(--game-accent);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.btn-exit:hover { filter: brightness(1.1); }

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  padding: 0 16px 16px;
}

@media (min-width: 1400px) {
  .games-grid { grid-template-columns: repeat(10, 1fr); }
}

.game-card {
  background: var(--game-card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.game-card:hover {
  background: var(--game-card-hover);
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.4);
}

.game-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.game-name {
  padding: 6px 4px 2px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-code {
  padding: 0 4px 6px;
  font-size: 11px;
  color: #888;
}

/* ===== Play View ===== */
#view-play {
  background: #0a0a14;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.play-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #111;
  flex-shrink: 0;
}

.play-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.play-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.play-brand-img {
  height: 28px;
  width: auto;
  display: block;
}

.play-brand .logo-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e0e0e0;
}

.btn-back {
  background: transparent;
  color: var(--game-text);
  border: 1px solid #444;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
}

.btn-back:hover { background: #222; }

.play-main {
  flex: 1;
  display: grid;
  grid-template-columns: 140px 1fr 140px;
  overflow: hidden;
  min-height: 0;
}

.play-sidebar {
  background: var(--game-sidebar-bg);
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.play-iframe-wrap {
  flex: 1;
  min-height: 0;
  background: #1a1a2e;
}

#game-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.sidebar-card {
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(255,255,255,0.05);
  transition: var(--transition);
}

.sidebar-card:hover { background: rgba(255,255,255,0.1); }

.sidebar-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.sidebar-card span {
  display: block;
  padding: 4px;
  font-size: 11px;
  color: var(--game-text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .calc-nav { flex-direction: column; gap: 12px; }
  .play-main { grid-template-columns: 1fr; }
  .play-sidebar { display: none; }
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
  }
  .search-input { width: 100%; max-width: 200px; }
}
