/* ===== CSS VARIABLES ===== */
:root {
  --bg:        #0f380f;
  --bg-dark:   #0a2a0a;
  --bg-mid:    #1a4a1a;
  --green:     #306230;
  --bright:    #8bac0f;
  --text:      #9bbc0f;
  --text2:     #8bac0f;
  --text-dim:  #4a6c10;
  --highlight: #c8d870;
  --red:       #e0302a;
  --border:    #306230;
  --font-px:   'Courier New', Courier, monospace;
  --hdr-h:     44px;
  --sub-h:     26px;
  --score-h:   38px;
  --action-h:  40px;
  --dpad-h:    126px;
  --ad-h:      46px;
  --tabbar-h:  50px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font-px);
  background: var(--bg-dark);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--text); text-decoration: none; }
a:hover { color: var(--highlight); text-decoration: underline; }
button { cursor: pointer; font-family: var(--font-px); }

/* ===== MOBILE BASE ===== */
@media (max-width: 767px) {
  html, body { height: 100%; overflow: hidden; }
  .app-wrap {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
  }
}

/* ===== DESKTOP BASE ===== */
@media (min-width: 768px) {
  .app-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
  }
}

/* ================================================================
   HEADER
   ================================================================ */
.hdr {
  background: var(--bg-dark);
  border-bottom: 2px solid var(--green);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Mobile header */
@media (max-width: 767px) {
  .hdr { height: var(--hdr-h); padding: 0 10px; gap: 8px; }
  .hdr-logo  { display: none; }
  .hdr-nav   { display: none; }
  .hdr-back  { display: none; }
}

/* Desktop header */
@media (min-width: 768px) {
  .hdr {
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0 24px;
    gap: 20px;
  }
  .hdr-back { display: none; }
}

.hdr-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  background: var(--bg-mid);
  border: 1px solid var(--green);
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  flex-shrink: 0;
}
.hdr-back:hover { border-color: var(--bright); color: var(--highlight); text-decoration: none; }

.hdr-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.hdr-logo img { width: 28px; height: 28px; }

.hdr-title {
  font-size: 14px;
  font-weight: bold;
  color: var(--text);
  letter-spacing: 2px;
  text-transform: uppercase;
}
@media (max-width: 767px) {
  .hdr-title { flex: 1; text-align: center; }
}
@media (min-width: 768px) {
  .hdr-title { flex: 1; }
  .hdr-title:hover { color: var(--highlight); }
}

.hdr-nav {
  display: flex;
  align-items: center;
}
.hdr-nav a {
  font-size: 14px;
  color: var(--text-dim);
  padding: 4px 10px;
  border: 1px solid var(--bg-mid);
  border-radius: 3px;
  white-space: nowrap;
}
.hdr-nav a:hover { color: var(--text2); border-color: var(--green); text-decoration: none; }

.hdr-sound {
  width: 34px;
  height: 30px;
  background: var(--bg-mid);
  border: 1px solid var(--green);
  border-radius: 4px;
  color: var(--text);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hdr-sound:active { background: var(--green); }
@media (min-width: 768px) {
  .hdr-sound:hover { border-color: var(--bright); }
}

/* ================================================================
   SUBTITLE BAR
   ================================================================ */
.subtitle-bar {
  height: var(--sub-h);
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-bottom: 1px solid var(--bg-mid);
}
@media (max-width: 767px) {
  .subtitle-bar { display: none; }
}
.subtitle-bar h2 {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 1px;
  font-weight: normal;
}

/* ================================================================
   BREADCRUMB BAR (Desktop)
   ================================================================ */
.breadcrumb-bar {
  background: var(--bg-dark);
  border-bottom: 1px solid var(--bg-mid);
  padding: 6px 24px;
  flex-shrink: 0;
}
@media (max-width: 767px) {
  .breadcrumb-bar { display: none; }
}
@media (min-width: 768px) {
  .breadcrumb-bar { display: block; }
}
.breadcrumb-bar ol {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-dim);
}
.breadcrumb-bar a {
  color: var(--text-dim);
  font-size: 14px;
}
.breadcrumb-bar a:hover {
  color: var(--text2);
  text-decoration: none;
}
.breadcrumb-bar .sep {
  color: var(--bg-mid);
  margin: 0 2px;
}

/* ================================================================
   MAIN GRID
   ================================================================ */

/* Mobile: vertical stack, game-core fills available space */
@media (max-width: 767px) {
  .main-grid {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }
  .game-core {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  /* Side panels hidden on mobile */
  .side-left  { display: none !important; }
  .side-right { display: none !important; }
  /* Tab panels are absolute overlay */
  .tab-panel {
    display: none;
    position: absolute;
    inset: 0;
    background: var(--bg);
    overflow-y: auto;
    z-index: 20;
    padding: 16px;
  }
  .tab-panel.active { display: block; }
  /* D-pad visible */
  .dpad { display: flex; }
  /* Tabbar visible */
  .tabbar { display: flex; }
  /* Page article hidden */
  .page-article { display: none; }
  /* Footer hidden */
  .footer { display: none; }
}

/* Desktop: three-column grid */
@media (min-width: 768px) {
  .main-grid {
    max-width: 1080px;
    margin: 30px auto;
    padding: 0 24px;
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    gap: 24px;
    align-items: start;
  }
  .game-core {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }
  /* Side panels visible */
  .side-left  { display: flex; }
  .side-right { display: flex; }
  /* Tab panels hidden */
  .tab-panel { display: none !important; }
  /* D-pad hidden */
  .dpad { display: none !important; }
  /* Tabbar hidden */
  .tabbar { display: none !important; }
  /* Page article visible */
  .page-article { display: block; }
  /* Footer visible */
  .footer { display: flex; }
}

/* ================================================================
   SIDE PANELS (Desktop only)
   ================================================================ */
.side-left,
.side-right {
  flex-direction: column;
  gap: 16px;
}

.side-card {
  background: var(--bg-dark);
  border: 1px solid var(--bg-mid);
  border-radius: 6px;
  padding: 14px;
}
.side-card-title {
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--bg-mid);
}
.side-card p {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 6px;
  line-height: 1.6;
}
.side-card p strong { color: var(--text2); }

kbd {
  background: var(--bg-mid);
  color: var(--text2);
  border: 1px solid var(--green);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-px);
  font-size: 14px;
}

.empty-text {
  font-size: 11px;
  color: var(--text-dim);
}

/* ================================================================
   SCORE BAR
   ================================================================ */
.score-bar {
  background: var(--bg-dark);
  border-bottom: 1px solid var(--bg-mid);
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-shrink: 0;
}
@media (max-width: 767px) {
  .score-bar {
    height: var(--score-h);
    padding: 0 8px;
  }
}
@media (min-width: 768px) {
  .score-bar {
    width: 100%;
    height: var(--score-h);
    padding: 0 12px;
    border: 1px solid var(--bg-mid);
    border-radius: 6px;
  }
}

.score-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.score-label {
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.score-val {
  font-size: 14px;
  font-weight: bold;
  color: var(--text);
  min-width: 28px;
  text-align: right;
}

.speed-sel {
  background: var(--bg-mid);
  color: var(--text);
  border: 1px solid var(--green);
  border-radius: 3px;
  font-family: var(--font-px);
  font-size: 14px;
  padding: 2px 4px;
  cursor: pointer;
}

.ai-btn {
  background: var(--bg-mid);
  color: var(--text2);
  border: 1px solid var(--green);
  border-radius: 3px;
  font-size: 14px;
  padding: 3px 7px;
  font-family: var(--font-px);
  letter-spacing: 1px;
  transition: all 0.15s;
}
.ai-btn.active {
  background: var(--bright);
  color: var(--bg-dark);
  border-color: var(--bright);
}
.ai-btn:active { opacity: 0.8; }

/* ================================================================
   CANVAS AREA
   ================================================================ */
.canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
}
@media (max-width: 767px) {
  .canvas-wrap {
    flex: 1;
    min-height: 0;
  }
}
@media (min-width: 768px) {
  .canvas-wrap {
    width: 440px;
    height: 440px;
    border: 2px solid var(--green);
    border-radius: 6px;
    box-shadow: 0 0 24px rgba(48, 98, 48, 0.3);
  }
}

/* Scanline overlay */
.canvas-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  pointer-events: none;
  z-index: 1;
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  position: relative;
  z-index: 0;
}
@media (max-width: 767px) {
  #gameCanvas {
    box-shadow: 0 0 18px rgba(139, 172, 15, 0.25), 0 0 40px rgba(139, 172, 15, 0.08);
  }
}

/* ================================================================
   OVERLAY
   ================================================================ */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 42, 10, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px;
}
@media (max-width: 767px) {
  .overlay-box { gap: 12px; }
}

.overlay-title {
  font-weight: bold;
  color: var(--text);
  letter-spacing: 2px;
  text-transform: uppercase;
}
@media (max-width: 767px) {
  .overlay-title { font-size: 18px; }
}
@media (min-width: 768px) {
  .overlay-title { font-size: 22px; letter-spacing: 3px; }
}

.overlay-sub {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 1px;
}
@media (min-width: 768px) {
  .overlay-sub { letter-spacing: 2px; }
}

.start-btn {
  background: var(--green);
  color: var(--text);
  border: 2px solid var(--bright);
  padding: 10px 32px;
  font-size: 14px;
  font-family: var(--font-px);
  letter-spacing: 2px;
  text-transform: uppercase;
  border-radius: 4px;
  transition: all 0.15s;
}
.start-btn:active { background: var(--bright); color: var(--bg-dark); }
@media (min-width: 768px) {
  .start-btn:hover { background: var(--bright); color: var(--bg-dark); }
}

/* ================================================================
   AI LABEL
   ================================================================ */
.ai-label {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(48, 98, 48, 0.85);
  color: var(--text);
  font-size: 14px;
  padding: 3px 7px;
  border: 1px solid var(--bright);
  border-radius: 3px;
  letter-spacing: 1px;
  z-index: 5;
  display: none;
}
.ai-label.visible { display: block; }

/* ================================================================
   ACTION BAR
   ================================================================ */
.action-bar {
  background: var(--bg-dark);
  border-top: 1px solid var(--bg-mid);
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-shrink: 0;
  gap: 6px;
}
@media (max-width: 767px) {
  .action-bar {
    height: var(--action-h);
    padding: 0 8px;
  }
}
@media (min-width: 768px) {
  .action-bar {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--bg-mid);
    border-radius: 6px;
    justify-content: center;
    gap: 10px;
  }
}

.act-btn {
  height: 28px;
  background: var(--bg-mid);
  color: var(--text2);
  border: 1px solid var(--green);
  border-radius: 3px;
  font-size: 14px;
  font-family: var(--font-px);
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.12s;
}
@media (max-width: 767px) {
  .act-btn { flex: 1; }
}
@media (min-width: 768px) {
  .act-btn { padding: 0 18px; }
}
.act-btn:active:not(:disabled) { background: var(--green); color: var(--highlight); }
.act-btn:disabled { opacity: 0.3; cursor: not-allowed; }
@media (min-width: 768px) {
  .act-btn:hover:not(:disabled) { border-color: var(--bright); color: var(--text); }
}

.act-btn-primary {
  background: var(--green);
  color: var(--text);
  border-color: var(--bright);
}
.act-btn-primary:active { background: var(--bright); color: var(--bg-dark); }
@media (min-width: 768px) {
  .act-btn-primary:hover:not(:disabled) { background: var(--bright); color: var(--bg-dark); }
}

/* ================================================================
   D-PAD (Mobile only)
   ================================================================ */
.dpad {
  height: var(--dpad-h);
  background: var(--bg-dark);
  border-top: 1px solid var(--bg-mid);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}
.dpad-inner {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(3, 40px);
  gap: 3px;
}
.dpad-btn {
  width: 40px;
  height: 40px;
  background: var(--bg-mid);
  color: var(--text);
  border: 2px solid var(--green);
  border-radius: 5px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.dpad-btn:active { background: var(--green); border-color: var(--bright); color: var(--highlight); }
.dpad-btn.hint-glow {
  background: var(--green);
  border-color: var(--highlight);
  color: var(--highlight);
  box-shadow: 0 0 10px rgba(200, 216, 112, 0.7);
  animation: hint-pulse 0.4s ease-in-out infinite alternate;
}
.dpad-center {
  width: 40px;
  height: 40px;
  background: var(--bg-mid);
  border: 2px solid var(--bg-mid);
  border-radius: 5px;
}

@keyframes hint-pulse {
  from { box-shadow: 0 0 6px rgba(200, 216, 112, 0.5); }
  to   { box-shadow: 0 0 14px rgba(200, 216, 112, 0.9); }
}

/* ================================================================
   TAB PANELS (Mobile only)
   ================================================================ */
.tab-panel-inner h3 {
  font-size: 14px;
  color: var(--text);
  letter-spacing: 2px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--green);
  text-transform: uppercase;
}
.tab-panel-inner p {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 8px;
  line-height: 1.7;
}
.tab-panel-inner ul {
  padding-left: 1.2em;
  font-size: 14px;
  color: var(--text2);
}
.tab-panel-inner li { margin-bottom: 8px; line-height: 1.6; }

/* Record items (shared between side panel and tab panel) */
.record-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--bg-mid);
  font-size: 14px;
  color: var(--text2);
}
.record-item:first-child .score-num { color: var(--highlight); font-weight: bold; }

/* ================================================================
   AD BAR
   ================================================================ */
.ad-bar {
  flex-shrink: 0;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}
@media (max-width: 767px) {
  .ad-bar { height: var(--ad-h); }
}
@media (min-width: 768px) {
  .ad-bar {
    max-width: 1080px;
    margin: 10px auto 0;
    padding: 0 24px;
    height: 60px;
    background: none;
    border: none;
    border-radius: 0;
    width: calc(100% - 48px);
  }
}
.ad-bar a { color: var(--text-dim); }
.ad-bar a:hover { color: var(--text2); text-decoration: none; }

/* ================================================================
   TAB BAR (Mobile only)
   ================================================================ */
.tabbar {
  height: var(--tabbar-h);
  flex-shrink: 0;
  background: var(--bg-dark);
  border-top: 1px solid var(--bg-mid);
  display: flex;
  gap: 0;
  padding: 0 4px;
}
.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-px);
  font-size: 12px;
  letter-spacing: 0.5px;
  padding: 0;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.tab:active { background: rgba(48, 98, 48, 0.3); }
.tab.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(139, 172, 15, 0.08) 0%, transparent 100%);
  font-weight: bold;
}
.tab-icon { font-size: 17px; line-height: 1; }
.tab-label { font-size: 11px; line-height: 1; }

/* ================================================================
   ARTICLE CONTENT (Desktop only)
   ================================================================ */
.page-article {
  max-width: 1080px;
  margin: 40vh auto 0;
  padding: 0 24px;
}
.page-article section {
  margin-bottom: 30px;
  background: var(--bg-dark);
  border: 1px solid var(--bg-mid);
  border-radius: 6px;
  padding: 20px 24px;
}
.page-article h2 {
  font-size: 14px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bg-mid);
}
.page-article h3 {
  font-size: 14px;
  color: var(--text2);
  margin: 14px 0 8px;
}
.page-article p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.9;
  margin-bottom: 10px;
}
.page-article ul {
  padding-left: 1.4em;
  color: var(--text-dim);
  font-size: 14px;
}
.page-article li { margin-bottom: 8px; line-height: 1.7; }
.page-article strong { color: var(--text2); }
.page-article dt {
  font-size: 14px;
  color: var(--text2);
  font-weight: bold;
  margin: 14px 0 4px;
}
.page-article dd {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.8;
  padding-left: 1em;
  border-left: 2px solid var(--bg-mid);
}

/* ================================================================
   FOOTER (Desktop only)
   ================================================================ */
.footer {
  max-width: 1080px;
  margin: 30px auto 0;
  padding: 20px 24px 30px;
  border-top: 1px solid var(--bg-mid);
  text-align: center;
  flex-direction: column;
  gap: 6px;
}
.footer p { font-size: 14px; color: var(--text-dim); }
.footer a { color: var(--text-dim); }
.footer a:hover { color: var(--text2); text-decoration: none; }
.icp { font-size: 14px; }

/* ================================================================
   CONTENT ENHANCEMENT STYLES
   ================================================================ */
.tip-box {
  background-color: rgba(139, 172, 15, 0.1);
  border: 1px solid var(--bright);
  border-radius: 6px;
  padding: 14px 18px;
  margin: 18px 0;
}
.tip-title {
  color: var(--text);
  font-weight: bold;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tip-title::before { content: "💡"; }

.example-block {
  background-color: var(--bg-dark);
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 16px 20px;
  margin: 20px 0;
}
.example-header {
  color: var(--text);
  font-weight: bold;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bg-mid);
}

.step-guide { counter-reset: step-counter; margin: 20px 0; }
.step-item {
  position: relative;
  padding-left: 32px;
  margin-bottom: 14px;
  min-height: 28px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}
.step-item::before {
  counter-increment: step-counter;
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  background-color: var(--green);
  color: var(--text);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
}

.game-feature {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.feature-card {
  background-color: var(--bg-dark);
  border: 1px solid var(--bg-mid);
  border-radius: 6px;
  padding: 14px;
  text-align: center;
}
.feature-icon { font-size: 24px; margin-bottom: 8px; display: block; }
.feature-title { color: var(--text); font-weight: bold; margin-bottom: 6px; font-size: 14px; }
.feature-desc { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

/* ================================================================
   RESPONSIVE FINE-TUNING
   ================================================================ */
@media (max-width: 767px) {
  .game-feature { grid-template-columns: 1fr; gap: 12px; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  .game-feature { grid-template-columns: repeat(2, 1fr); }
}
