/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  /* manipulation = pan + pinch-zoom allowed, double-tap zoom disabled.
     Must NOT be 'none' here — child elements need touch-action: pan-y
     for native scrolling to work (touch-action is intersection of ancestors). */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: #000;
  color: #fff;
  font-family: monospace;
  font-size: 14px;
  line-height: 1.4;
}

/* ── App container ───────────────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; }

.screen-body {
  flex: 1;
  overflow: hidden;
  padding: 0.6rem 1rem;
  position: relative;
}

/* Top / Ranking / Settings: scrollable on small screens */
#screen-top      .screen-body,
#screen-ranking  .screen-body,
#screen-opsetting .screen-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

/* ── Overlay ─────────────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.overlay.visible { display: flex; }
.overlay-box {
  border: 1px solid #fff;
  padding: 1.5rem 2rem;
  max-width: 480px;
  width: 90%;
  text-align: center;
  background: #000;
}
.overlay-box p { margin-bottom: 0.8rem; line-height: 1.7; }
.disclaimer-main { color: #fff; font-size: 0.95rem; }
.disclaimer-sub  { color: #aaa; font-size: 0.85rem; }
.disclaimer-sub a { color: #8cf; text-decoration: underline; }
.overlay-btn {
  margin-top: 0.8rem;
  background: #000;
  color: #fff;
  border: 1px solid #fff;
  padding: 0.6rem 2.5rem;
  font-family: monospace;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
.overlay-btn:active, .overlay-btn.pressed { background: #fff; color: #000; }

/* ── Top page ────────────────────────────────────────────────────────────── */
.top-left-info {
  position: absolute;
  top: 0.5rem;
  left: 1rem;
  color: #fff;
  font-size: 0.85rem;
}
.top-ranking-box {
  position: absolute;
  top: 0.5rem;
  right: 1rem;
  text-align: right;
  font-size: 0.8rem;
}
.top-ranking-title { color: #fff; margin-bottom: 0.3rem; }
.top-ranking-list-item { color: #ccc; white-space: nowrap; }

.top-center { margin-top: 3.5rem; text-align: center; }
.game-title  { font-size: 1rem; color: #fff; margin-bottom: 1.2rem; letter-spacing: 2px; }
.menu-list   { display: inline-block; text-align: left; }

/* Top menu items – touchable, bigger, spaced */
.top-menu-item {
  display: flex;
  align-items: center;
  padding: 0.45rem 0;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
}
.top-menu-item .cursor-char {
  width: 1.2em;
  display: inline-block;
  color: #fff;           /* cursor > stays white */
  flex-shrink: 0;
}
.top-menu-item .item-num   { color: #fff; }
.top-menu-item .item-label { color: #fff; padding-left: 0.5em; }

/* Selected: number becomes red, cursor stays white */
.top-menu-item.selected .item-num   { color: #f00; }
.top-menu-item.selected .item-label { color: #f00; }
/* cursor-char NOT red */

/* Game menu items – keyboard only */
.game-menu-item {
  display: flex;
  align-items: center;
  padding: 0.15rem 0;
  font-size: 0.9rem;
}
.game-menu-item .cursor-char { width: 1.2em; display: inline-block; flex-shrink: 0; color: #fff; }
.game-menu-item .item-num    { color: #fff; }
.game-menu-item .item-label  { color: #fff; padding-left: 0.5em; }

/* Selected: number red, cursor NOT red */
.game-menu-item.selected .item-num   { color: #f00; }
.game-menu-item.selected .item-label { color: #f00; }

.notice-box   { margin-top: 1.5rem; text-align: center; }
.notice-title { color: #fff; margin-bottom: 0.4rem; font-size: 0.9rem; }
.notice-item  { color: #ccc; font-size: 0.85rem; line-height: 1.6; }

/* ── Bottom area ─────────────────────────────────────────────────────────── */
.bottom-area { flex-shrink: 0; padding: 0 0.5rem 0.3rem; }

.bottom-links { text-align: left; margin-bottom: 0.2rem; }
.bottom-link-btn {
  color: #888;
  font-size: 0.75rem;
  text-decoration: none;
  border: 1px solid #444;
  padding: 0.2rem 0.5rem;
  touch-action: manipulation;
}
.bottom-link-btn:hover { color: #fff; border-color: #fff; }

.touch-indicator  { color: #0f0; font-size: 0.75rem; text-align: right; padding-right: 0.5rem; margin-bottom: 0.1rem; }
.late-night-msg   { color: #0f0; text-align: center; font-size: 0.85rem; margin: 0.5rem 0; }
.key-guide        { color: #888; font-size: 0.75rem; text-align: center; margin-bottom: 0.2rem; }

.guide-bar {
  border-top: 1px solid #555;
  padding-top: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
/* flex-shrink:1 so guide-text yields space to buttons before overflowing */
.guide-text { font-size: 0.7rem; color: #fff; white-space: nowrap; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; }

/* ── Action buttons ──────────────────────────────────────────────────────── */
.action-buttons { display: flex; gap: 0.3rem; flex-shrink: 0; }

.act-btn {
  background: #000;
  color: #fff;
  border: 1px solid #fff;
  font-family: monospace;
  font-size: 0.7rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  min-width: 52px;
  min-height: 38px;
  padding: 0.3rem 0.4rem;
}
.act-btn:active, .act-btn.pressed { background: #fff; color: #000; }

.btn-size-small .act-btn  { min-width: 42px; min-height: 30px; font-size: 0.65rem; }
.btn-size-large .act-btn  { min-width: 70px; min-height: 52px; font-size: 0.85rem; }
.btn-dir-vertical .action-buttons { flex-direction: column; }

/* ── Game screen ─────────────────────────────────────────────────────────── */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.4rem 0.8rem 0.2rem;
  flex-shrink: 0;
}
.timer-display { color: #0f0; font-size: 0.95rem; white-space: nowrap; }
#game-breadcrumb { color: #fff; font-size: 0.85rem; }

.game-body {
  flex: 1;
  overflow: hidden;
  padding: 0.3rem 1.5rem;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.countdown-number { font-size: 5rem; color: #fff; line-height: 1; margin-bottom: 0.5rem; }
.countdown-label  { color: #888; font-size: 0.8rem; }
.countdown-keyguide { margin-top: 1.5rem; font-size: 0.75rem; color: #555; text-align: center; line-height: 1.8; }

/* ── Slot setting table ───────────────────────────────────────────────────── */
.slot-table { font-size: 0.85rem; }

.slot-header-row {
  display: flex;
  align-items: center;
  padding: 0 0 0.15rem 0;
}

.slot-row {
  display: flex;
  align-items: center;
  padding: 0.1rem 0;
}

/* Cursor: white always */
.slot-cursor    { width: 1.2em; display: inline-block; flex-shrink: 0; color: #fff; }
.slot-num-label { width: 1.5em; flex-shrink: 0; color: #fff; }  /* white always */

/* Selected row: number becomes red, cursor stays white */
.slot-row.selected .slot-cursor    { color: #fff; }  /* NOT red */
.slot-row.selected .slot-num-label { color: #f00; }  /* number is red */
.slot-row.selected .slot-label-col { color: #f00; }

.slot-label-col { width: 15ch; flex-shrink: 0; color: #fff; }

/* NOW/SET header labels – green */
.slot-col-head  { font-size: 0.75em; color: #0f0; }
.slot-now-head  { width: 12ch; }
.slot-set-head  { width: 12ch; }

/* Values and arrow – white */
.slot-now-val  { color: #fff; width: 12ch; }
.slot-arrow-col { color: #fff; width: 5ch; flex-shrink: 0; }
.slot-set-val  { color: #fff; }

/* ── Result screen ───────────────────────────────────────────────────────── */
.result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 0.8rem;
}
.result-title { font-size: 1.4rem; letter-spacing: 3px; }
.result-time  { color: #0f0; font-size: 1.2rem; }
.result-rank  { color: #ff0; font-size: 0.9rem; }
.result-late  { color: #0f0; font-size: 0.8rem; }

.result-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  max-width: 300px;
}
.result-input-group input {
  background: #000;
  color: #fff;
  border: 1px solid #fff;
  font-family: monospace;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  width: 100%;
  touch-action: manipulation;
}
.result-input-group input:focus { outline: none; border-color: #0f0; }
.result-input-group label { color: #aaa; font-size: 0.8rem; align-self: flex-start; }
.result-btn {
  background: #000;
  color: #fff;
  border: 1px solid #fff;
  font-family: monospace;
  font-size: 0.9rem;
  padding: 0.4rem 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
  min-width: 120px;
}
.result-btn:active, .result-btn.pressed { background: #fff; color: #000; }

/* ── Ranking screen ──────────────────────────────────────────────────────── */
#screen-ranking .screen-body { overflow-y: auto; }

.section-header { color: #fff; margin-bottom: 0.6rem; font-size: 0.9rem; }

.ranking-tables { display: flex; gap: 1rem; font-size: clamp(0.75rem, 2vw, 1rem); overflow-x: auto; margin-bottom: 0.6rem; }
.ranking-col    { min-width: 140px; flex: 1; }
.ranking-col-title { color: #fff; margin-bottom: 0.3rem; font-size: 0.8em; white-space: nowrap; }
.ranking-entry { color: #ccc; white-space: nowrap; line-height: 1.7; }
.ranking-entry.rank1 { color: #ff0; }
.ranking-entry.rank2 { color: #aaa; }
.ranking-entry.rank3 { color: #c84; }
.ranking-device { color: #555; font-size: 0.8em; }

.top-comment-section { margin-top: 0.5rem; font-size: 0.8rem; }
.top-comment-entry { color: #ccc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ranking-exit-row { margin-top: 0.8rem; text-align: center; }
.exit-btn {
  background: #000;
  color: #fff;
  border: 1px solid #fff;
  font-family: monospace;
  font-size: 0.9rem;
  padding: 0.3rem 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
  min-width: 80px;
}
.exit-btn:active, .exit-btn.pressed { background: #fff; color: #000; }

/* ── Operation Setting ───────────────────────────────────────────────────── */
.opsetting-body { padding: 0.5rem; }
.opsetting-section-title {
  color: #888;
  font-size: 0.8rem;
  margin: 0.6rem 0 0.3rem;
  border-bottom: 1px solid #333;
  padding-bottom: 0.2rem;
}

.opsetting-item {
  display: flex;
  align-items: center;
  padding: 0.2rem 0;
  gap: 0;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 38px;
  font-size: 0.85rem;
}
.opsetting-item .cursor-char { width: 1.2em; color: #fff; flex-shrink: 0; }
.opsetting-item .item-num    { color: #fff; flex-shrink: 0; }
.opsetting-item .item-label  { color: #fff; flex: 1; padding-left: 0.5em; }
.opsetting-item .item-val    { color: #0f0; margin-left: auto; white-space: nowrap; }

/* Selected: number red, cursor stays white */
.opsetting-item.selected .item-num   { color: #f00; }
.opsetting-item.selected .item-label { color: #f00; }

/* ── Exit screen ─────────────────────────────────────────────────────────── */
.exit-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  font-size: 1rem;
  color: #fff;
}

/* ── Admin login ─────────────────────────────────────────────────────────── */
.admin-login-wrap { max-width: 360px; margin: 4rem auto; padding: 1.5rem; border: 1px solid #444; }
.admin-login-wrap h1 { font-size: 1rem; margin-bottom: 1.5rem; text-align: center; }
.admin-field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; }
.admin-field label { color: #888; font-size: 0.8rem; }
.admin-field input {
  background: #000; color: #fff; border: 1px solid #555;
  padding: 0.4rem 0.6rem; font-family: monospace; font-size: 0.9rem;
}
.admin-field input:focus { outline: none; border-color: #fff; }
.admin-submit { width: 100%; background: #000; color: #fff; border: 1px solid #fff; padding: 0.5rem; font-family: monospace; font-size: 0.9rem; cursor: pointer; }
.admin-submit:hover { background: #111; }
.admin-error { color: #f55; font-size: 0.8rem; margin-top: 0.5rem; min-height: 1em; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  body { font-size: 12px; }
  .game-title { font-size: 0.85rem; }
  .top-menu-item { font-size: 0.9rem; min-height: 40px; }
  .top-center { margin-top: 2.8rem; }
  .ranking-tables { flex-direction: column; }
  .ranking-col { min-width: unset; }
  .guide-text { font-size: 0.6rem; }
  .act-btn { min-width: 44px; min-height: 36px; font-size: 0.65rem; }
  .top-ranking-box { font-size: 0.7rem; }
}

/* Portrait phones: stack action buttons vertically to prevent overflow */
@media (orientation: portrait) and (max-width: 600px) {
  .guide-bar {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.3rem;
  }
  .guide-text {
    flex-basis: 100%;
    order: 1;
  }
  .action-buttons {
    order: 2;
    flex-direction: column;
    gap: 0.15rem;
    flex-shrink: 0;
  }
  .act-btn {
    min-height: 30px;
    min-width: 56px;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
  }
}

/* Desktop: guide text centered, buttons stay on the right */
@media (min-width: 900px) {
  body { font-size: 16px; }
  .act-btn { min-width: 64px; min-height: 44px; }
  .guide-bar { justify-content: space-between; }
  .guide-text { flex: 1; text-align: center; }
}
