:root {
  --bg-primary: #0b1120;
  --bg-secondary: #131d31;
  --bg-card: #182338;
  --bg-card-hover: #22324f;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-gold: #f59e0b;
  --accent-blue: #38bdf8;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-purple: #a855f7;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-gold: rgba(245, 158, 11, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  padding: 16px 12px;
  background-image: radial-gradient(circle at 50% 0%, #1e3a5f 0%, var(--bg-primary) 75%);
}

.container {
  max-width: 860px;
  margin: 0 auto;
}

/* Màn hình đăng nhập */
.login-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(circle at center, #1e293b 0%, #0b1120 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 9999;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.login-icon {
  font-size: 44px;
  margin-bottom: 12px;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-gold);
  margin-bottom: 6px;
}

.login-card p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-login {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
  transition: transform 0.15s, opacity 0.15s;
}

.btn-login:active {
  transform: scale(0.98);
}

.login-error {
  color: var(--accent-red);
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  min-height: 20px;
}

/* Header */
header {
  margin-bottom: 18px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

header h1 {
  font-size: clamp(20px, 4.5vw, 26px);
  font-weight: 800;
  background: linear-gradient(135deg, #fef08a, #f59e0b, #fbbf24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.btn-logout {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

header p {
  color: var(--text-muted);
  font-size: 13px;
}

/* Panel */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.panel-featured {
  border-color: var(--border-gold);
}

.panel-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent-gold);
  margin-bottom: 10px;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

/* Inputs & Form */
.grid-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .grid-inputs {
    grid-template-columns: 1fr;
  }
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.badge-code {
  color: var(--accent-gold);
  font-weight: 800;
  font-size: 13px;
}

.input-row {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="password"],
input[type="datetime-local"] {
  background: #090e1a;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-main);
  padding: 12px 14px;
  font-size: 16px; /* 16px to prevent iOS Safari auto-zoom */
  font-weight: 600;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--accent-gold);
}

.btn-secondary {
  background: #25334c;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.input-hint {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
  line-height: 1.3;
}

/* Env Bar */
.env-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 600px) {
  .env-bar {
    grid-template-columns: repeat(3, 1fr);
  }
}

.env-pill {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}

.env-pill .env-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.env-pill .env-val {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-blue);
}

.highlight-gold { color: var(--accent-gold) !important; }
.highlight-red  { color: var(--accent-red)  !important; }

/* Sprites */
.dice-sprite {
  width: 50px;
  height: 66px;
  background-image: url('face-index-sheet.png');
  background-size: 300px 66px;
  background-repeat: no-repeat;
  display: inline-block;
}

.dice-sprite-large {
  width: 90px;
  height: 120px;
  background-image: url('face-index-sheet.png');
  background-size: 540px 120px;
  background-repeat: no-repeat;
  display: inline-block;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}

.sprite-nai { background-position: 0 0; }
.sprite-bau { background-position: -50px 0; }
.sprite-ga  { background-position: -100px 0; }
.sprite-ca  { background-position: -150px 0; }
.sprite-cua { background-position: -200px 0; }
.sprite-tom { background-position: -250px 0; }

.dice-sprite-large.sprite-nai { background-position: 0 0; }
.dice-sprite-large.sprite-bau { background-position: -90px 0; }
.dice-sprite-large.sprite-ga  { background-position: -180px 0; }
.dice-sprite-large.sprite-ca  { background-position: -270px 0; }
.dice-sprite-large.sprite-cua { background-position: -360px 0; }
.dice-sprite-large.sprite-tom { background-position: -450px 0; }

/* 3 Prev Slots */
.prev-slots-container {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 12px 0 18px;
}

.prev-slot {
  flex: 1;
  max-width: 140px;
  background: #090e1a;
  border: 2px dashed rgba(245, 158, 11, 0.5);
  border-radius: 14px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s;
}

.prev-slot:active {
  transform: scale(0.97);
  border-color: var(--accent-gold);
}

.slot-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
  white-space: nowrap;
}

/* Prediction Result Box */
.prediction-box {
  border-radius: 14px;
  padding: 16px;
}

.forced-result {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(15, 23, 42, 0.95) 100%);
  border: 2px solid var(--accent-green);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

.avoid-result {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(15, 23, 42, 0.95) 100%);
  border: 2px solid var(--accent-red);
}

.res-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 12px;
}

.forced-badge { background: var(--accent-green); color: #fff; }
.avoid-badge  { background: var(--accent-red); color: #fff; }

.forced-showcase {
  display: flex;
  align-items: center;
  gap: 16px;
}

@media (max-width: 500px) {
  .forced-showcase {
    flex-direction: column;
    text-align: center;
  }
}

.forced-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.forced-face-name {
  font-size: 26px;
  font-weight: 900;
  color: #fef08a;
  line-height: 1.1;
}

.forced-position {
  font-size: 15px;
  color: var(--accent-blue);
  font-weight: 700;
}

.forced-formula, .forced-calc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.forced-formula code, .forced-calc code {
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--accent-gold);
  font-family: monospace;
}

.res-note {
  margin-top: 12px;
  font-size: 12px;
  color: #cbd5e1;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  line-height: 1.4;
}

.res-title {
  font-size: 17px;
  font-weight: 800;
  color: #fca5a5;
  margin-bottom: 6px;
}

.res-explain {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.4;
}

/* 6 Faces Grid */
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 12px 0;
}

@media (max-width: 540px) {
  .mapping-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.code-card {
  background: #090e1a;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.code-number {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-gold);
  margin-bottom: 2px;
}

.code-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

.avoid-card {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.08);
}

.avoid-tag {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent-red);
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 3px;
}

/* Formula Box */
.formula-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
  margin-top: 12px;
}

.formula-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: 6px;
}

.formula-code {
  color: #fff;
  font-family: monospace;
}

.formula-rules {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Data Table */
.table-container {
  margin-top: 14px;
  overflow-x: auto;
}

.table-header-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.data-table th {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
}

.face-tag {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

/* Modal Selector */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  padding: 16px;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: 18px;
  max-width: 360px;
  width: 100%;
  padding: 20px;
  text-align: center;
}

.modal-header {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent-gold);
  margin-bottom: 14px;
}

.modal-faces-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.modal-face-btn {
  background: #090e1a;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.modal-face-btn:active {
  border-color: var(--accent-gold);
  transform: scale(0.96);
}

.btn-close {
  background: #25334c;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 24px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

/* Live Clock Card */
.live-clock-card {
  background: linear-gradient(135deg, rgba(30, 58, 95, 0.4) 0%, rgba(15, 23, 42, 0.8) 100%);
  border: 1px solid var(--border-gold);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 16px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.clock-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.clock-time {
  font-size: 26px;
  font-weight: 900;
  color: var(--accent-gold);
  letter-spacing: 1px;
  font-family: monospace;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
}

.toggle-label input {
  accent-color: var(--accent-gold);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.clock-countdown {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Quick Codes */
.quick-codes-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn-tag {
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-tag:hover, .btn-tag.active-tag {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--accent-gold);
  color: #fef08a;
}

/* 24h Schedule Table */
.schedule-table-wrap {
  max-height: 420px;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  margin-top: 10px;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.schedule-table th {
  position: sticky;
  top: 0;
  background: #111a2e;
  padding: 10px 8px;
  text-align: left;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  z-index: 2;
}

.schedule-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.schedule-row {
  cursor: pointer;
  transition: background 0.15s;
}

.schedule-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.schedule-row-current {
  background: rgba(245, 158, 11, 0.12) !important;
  border-left: 3px solid var(--accent-gold);
}

.badge-live {
  background: var(--accent-gold);
  color: #000;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
}
