/* ===============================
   RESET / BASE
================================ */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top, #1b1b1b, #000);
  color: #fff;
}

.hidden {
  display: none !important;
}

/* ===============================
   LAYOUT
================================ */
.wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.table {
  width: 100%;
  max-width: 420px;
  padding: 16px;
}

.title {
  text-align: center;
  margin: 4px 0 6px;
}

.subtitle {
  text-align: center;
  font-size: 14px;
  color: #bbb;
  margin-bottom: 18px;
}

.zone {
  margin-bottom: 22px;
}

.label {
  font-size: 14px;
  margin-bottom: 8px;
  color: #9adfff;
}

/* ===============================
   CODE DISPLAY
================================ */
.code-display {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border-radius: 12px;
  background: #000;
  border: 1px solid #333;
  cursor: pointer;
}

.code-display span {
  width: 20px;
  text-align: center;
  font-size: 22px;
  color: #00ffcc;
}

/* shake */
.code-display.shake {
  animation: shake 0.3s;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

/* ===============================
   KEYPAD
================================ */
.keypad-wrapper {
  margin-top: 14px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.key {
  padding: 14px 0;
  font-size: 18px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(180deg, #2a2a2a, #111);
  color: #fff;
  box-shadow: inset 0 0 6px rgba(255,255,255,.08),
              0 2px 4px rgba(0,0,0,.6);
}

.key:active {
  transform: scale(0.96);
}

.key.danger {
  background: linear-gradient(180deg, #6a1b1b, #3a0e0e);
}

.key.ok {
  background: linear-gradient(180deg, #6cffc1, #19b87a);
  color: #003b26;
  font-weight: 700;
}

/* ===============================
   HINT
================================ */
.hint {
  margin-top: 10px;
  font-size: 12px;
  color: #aaa;
  text-align: center;
}

/* ===============================
   SAFE
================================ */
.safe {
  width: 260px;
  height: 300px;
  margin: 0 auto;
  position: relative;
}

.safe-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.safe-badge {
  display: flex;
  align-items: center;
  gap: 6px;
}

.safe-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff3b3b;
}

.safe.unlocked .safe-badge .dot {
  background: #3bff8f;
}

.safe-status {
  font-size: 12px;
  letter-spacing: 1px;
}

.safe-light {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #222;
}

.safe.unlocked .safe-light {
  background: #3bff8f;
  box-shadow: 0 0 8px #3bff8f;
}

/* ===============================
   SAFE BODY
================================ */
.safe-door {
  position: relative;
  width: 100%;
  height: 260px;
  border-radius: 16px;
  background: linear-gradient(145deg, #3a3a3a, #1a1a1a);
  box-shadow: inset 0 0 20px rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
}

.safe-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, #444, #111);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dial {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(180deg, #888, #444);
  position: relative;
  transition: transform 0.6s ease;
}

.dial-center {
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: #222;
}

.dial-notch {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 4px;
  height: 10px;
  background: #fff;
  transform: translateX(-50%);
}

.safe-bars {
  position: absolute;
  right: 10px;
  top: 40px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.safe-bars span {
  width: 6px;
  height: 24px;
  background: #111;
  border-radius: 3px;
}

/* ===============================
   OPEN GLOW
================================ */
.safe-open-glow {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: radial-gradient(circle, rgba(0,255,180,.35), transparent 70%);
  animation: glowPulse 1.4s infinite;
}

@keyframes glowPulse {
  0% { opacity: .2; }
  50% { opacity: .6; }
  100% { opacity: .2; }
}

/* ===============================
   ACTIONS
================================ */
.actions {
  margin-top: 14px;
  text-align: center;
}

.btn.primary {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(180deg, #ffd86a, #cfa21c);
  font-size: 16px;
  font-weight: 700;
  color: #3a2600;
}

.btn.primary:disabled {
  opacity: .4;
}

/* ===============================
   RULES BUTTON
================================ */
.rules-btn {
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: #9adfff;
  font-size: 14px;
}

/* ===============================
   RESULT
================================ */
.result {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  background: #111;
  text-align: center;
}

.result.win {
  background: linear-gradient(180deg, #0f3, #093);
  color: #003b26;
}

.win-reward {
  margin-top: 6px;
  font-size: 20px;
  font-weight: 800;
}

.rules-btn:active{ transform: scale(.98); }
.rules-icon{
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #ffd86b;
  background: rgba(255,216,107,.12);
  border: 1px solid rgba(255,216,107,.35);
}

.rules-modal.hidden{ display:none; }
.rules-modal{ position: fixed; inset:0; z-index: 9998; }

.rules-backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

.rules-sheet{
  position:absolute;
  left:50%;
  bottom:0;
  transform: translateX(-50%);
  width: min(520px, 92vw);
  max-height: 82vh;
  overflow:hidden;
  border-radius: 20px 20px 0 0;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(8, 24, 14, .96);
  box-shadow: 0 -18px 40px rgba(0,0,0,.55);
}

.rules-header{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.rules-title-wrap{
  display:flex;
  align-items:center;
  gap: 10px;
}

.rules-badge{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display:grid;
  place-items:center;
  background: rgba(255,216,107,.16);
  border: 1px solid rgba(255,216,107,.35);
}

.rules-title{ font-weight: 900; font-size: 16px; line-height: 1.1; }
.rules-subtitle{ opacity: .85; font-size: 12px; margin-top: 3px; }

.rules-close{
  width: 36px;
  height: 36px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius: 50%;
  background: rgba(255,215,0,.15);
  border: 1px solid rgba(255,215,0,.4);
  color: #ffd966;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
}
.rules-close:hover{ background: rgba(255,215,0,.3); }

.rules-body{
  padding: 14px;
  overflow:auto;
  max-height: calc(82vh - 64px);
}

.rules-section{ margin-bottom: 14px; }
.rules-h{ font-weight: 900; margin-bottom: 8px; color: #ffd86b; }
.rules-p{ opacity:.95; line-height: 1.45; }
.rules-ol{ margin:0; padding-left: 18px; line-height: 1.55; }

.rules-ok{
  width: 100%;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,216,107,.35);
  background: rgba(255,216,107,.12);
  color: #ffd86b;
  font-weight: 900;
  cursor: pointer;
}

/* ===============================
   RULES MODAL – NEUTRAL OVERRIDE
   (Override old green theme safely)
================================ */

/* sheet หลัก – เอาเขียวออก */
.rules-sheet{
  background: linear-gradient(180deg, #1a1a1a, #0d0d0d) !important;
  border: 1px solid rgba(255,255,255,.15);
}

/* header */
.rules-header{
  border-bottom: 1px solid rgba(255,255,255,.08);
}

/* badge */
.rules-badge{
  background: rgba(255,216,107,.16) !important;
  border: 1px solid rgba(255,216,107,.35) !important;
  color: #ffd86b;
}

/* title + subtitle */
.rules-title{ color: #ffffff; }
.rules-subtitle{ color: #aaaaaa; }

/* section header */
.rules-h{
  color: #ffd86b !important;
}

/* body text */
.rules-p,
.rules-ol,
.rules-ol li{
  color: #dddddd;
}

/* close button */
.rules-close{
  background: rgba(255,216,107,.12) !important;
  border: 1px solid rgba(255,216,107,.35) !important;
  color: #ffd86b;
}
.rules-close:hover{
  background: rgba(255,216,107,.28) !important;
}

/* ok button */
.rules-ok{
  background: linear-gradient(180deg, #ffd86a, #cfa21c) !important;
  color: #3a2600 !important;
  border: none !important;
}
/* ===============================
   CENTER MODAL (WRONG CODE)
================================ */
.center-modal{
  display: flex;
  align-items: center;
  justify-content: center;
}

/* override bottom-sheet behavior */
.center-modal .rules-sheet{
  position: relative;
  bottom: auto !important;
  left: auto !important;
  transform: none !important;

  width: min(420px, 92vw);
  max-height: 80vh;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.75);
}

/* backdrop เข้มขึ้น ให้รู้ว่ามี error */
.center-modal .rules-backdrop{
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(3px);
}
