:root {
  --bg: #140b06;
  --gold1: #f7dc8a;
  --gold2: #c8952f;
  --gold3: #8a5d16;
  --cream: #f3e4c8;
  --panel: #23150d;
  --ink: #f5e9d4;
  --muted: #bfa98a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: manipulation;
}
#app {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: var(--sat) var(--sar) 0 var(--sal);
  background: radial-gradient(ellipse at 50% 40%, #3a2213 0%, #1d110a 60%, #120a05 100%);
}
#mainCol { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#hud {
  flex: 0 0 auto; height: 26px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; font-size: 13px; color: var(--muted); letter-spacing: .02em;
}
#hudScore { color: var(--gold1); font-weight: 600; }
#stage { flex: 1 1 auto; position: relative; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#toast {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9);
  background: rgba(20, 11, 6, .88); border: 1px solid var(--gold3); color: var(--cream);
  padding: 10px 18px; border-radius: 12px; font-size: 16px; pointer-events: none;
  opacity: 0; transition: opacity .25s, transform .25s; white-space: nowrap; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* alt bar */
#bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 10px calc(8px + var(--sab));
  background: linear-gradient(#1b2030, #0f121c);
  border-top: 1px solid #4a3a22; box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
#bar button { font: inherit; color: inherit; cursor: pointer; }
.rb {
  flex: 1 1 0; max-width: 150px; min-width: 0; height: 46px; border-radius: 23px;
  background: linear-gradient(#262c3f, #161a27); border: 1.5px solid var(--gold3);
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.08);
}
.rb svg { width: 22px; height: 22px; fill: var(--gold1); flex: 0 0 auto; }
.rb b { font-weight: 600; font-size: 14px; color: var(--cream); white-space: nowrap; overflow: hidden; }
.rb:disabled { opacity: .35; }
.rb:active:not(:disabled) { transform: scale(.94); }
#bMain {
  flex: 0 0 auto; min-width: 118px; height: 54px; border-radius: 27px; padding: 0 18px;
  background: linear-gradient(#ffe9a3, #e2b24a 45%, #b07a1e 100%);
  border: 2px solid #7a5310; color: #2a1a06 !important; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 0 0 2px rgba(0,0,0,.4), 0 4px 14px rgba(232, 180, 70, .35), inset 0 2px 0 rgba(255,255,255,.6);
}
#bMain svg { width: 26px; height: 26px; fill: #2a1a06; }
#bMain:disabled { filter: grayscale(.7) brightness(.6); }
#bMain:active:not(:disabled) { transform: scale(.95); }
#bMain.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px rgba(0,0,0,.4), 0 0 22px rgba(255, 210, 100, .8), inset 0 2px 0 rgba(255,255,255,.6); } }

/* dar ekran: sadece simge */
@media (max-width: 760px) {
  .rb b { display: none; }
  .rb { max-width: 54px; }
  #bMain { min-width: 104px; font-size: 16px; padding: 0 12px; }
}
@media (max-height: 460px) {
  #bar { padding-top: 5px; padding-bottom: calc(5px + var(--sab)); }
  .rb { height: 40px; }
  #bMain { height: 44px; }
  #hud { height: 22px; font-size: 12px; }
}

/* overlay & panel */
.overlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(8, 4, 2, .65); z-index: 10; padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab));
}
.overlay.show { display: flex; }
.panel {
  position: relative; width: min(440px, 100%); max-height: 100%; overflow: auto;
  background: linear-gradient(#2c1b10, #1b110a); border: 1.5px solid var(--gold3); border-radius: 18px;
  padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.07);
}
.panel h2 { margin: 0 0 14px; font-family: Georgia, "Times New Roman", serif; color: var(--gold1); font-size: 24px; text-align: center; }
.panel p { color: var(--muted); line-height: 1.45; }
#menu { background: #0c0604; }
.menuBg {
  position: absolute; inset: 0; background: url(../ref/2.webp) center/cover no-repeat;
  filter: blur(3px) brightness(.45); transform: scale(1.05);
}
@media (orientation: portrait) { .menuBg { background-image: url(../ref/1.webp); } }
.menuPanel { background: rgba(28, 17, 10, .82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.menuPanel h1 {
  margin: 0; text-align: center; font-family: Georgia, "Times New Roman", serif; font-size: 44px; letter-spacing: .14em;
  background: linear-gradient(#fff1bd, #e0aa3e 60%, #a36f17); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sub { text-align: center; margin: 2px 0 16px; font-size: 14px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.levels button, .seg button, .menuBtns button, .mbtn {
  font: inherit; color: var(--cream); cursor: pointer; border-radius: 12px; border: 1.5px solid #5a4020;
  background: linear-gradient(#2e2a36, #1a1820);
}
.levels button { padding: 10px 6px; display: flex; flex-direction: column; gap: 3px; align-items: center; }
.levels b { font-size: 16px; }
.levels small { font-size: 11px; color: var(--muted); text-align: center; }
.levels button.on, .seg button.on { border-color: var(--gold1); background: linear-gradient(#5c4318, #33240c); box-shadow: 0 0 12px rgba(247, 220, 138, .25); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.row > span { color: var(--muted); font-size: 14px; }
.seg { display: flex; gap: 6px; }
.seg button { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.menuBtns { display: flex; gap: 10px; margin-top: 16px; }
.menuBtns button { flex: 1; padding: 13px; font-size: 17px; font-weight: 700; }
button.gold, .mbtn.gold {
  background: linear-gradient(#ffe9a3, #e2b24a 45%, #b07a1e); color: #2a1a06; border-color: #7a5310;
}
.ruleNote { font-size: 12px; margin: 12px 0 0; text-align: center; }
.mbtns { display: flex; gap: 10px; margin-top: 16px; }
.mbtn { flex: 1; padding: 12px; font-size: 16px; font-weight: 600; }
.setrow { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.toggle { width: 50px; height: 30px; border-radius: 15px; background: #3a3030; position: relative; border: 1px solid #5a4020; cursor: pointer; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #ccc; transition: left .2s; }
.toggle.on { background: #a67a22; }
.toggle.on::after { left: 23px; background: #fff5d8; }
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stats th, table.stats td { padding: 7px 4px; text-align: center; border-bottom: 1px solid rgba(255,255,255,.07); }
table.stats th { color: var(--gold1); font-weight: 600; }
table.stats td:first-child, table.stats th:first-child { text-align: left; }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.themes button { font: inherit; color: var(--cream); background: #1a1410; border: 2px solid #4a3a22; border-radius: 12px; padding: 6px; cursor: pointer; }
.themes button.on { border-color: var(--gold1); }
.themes canvas { width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; }
.big { font-size: 20px; text-align: center; color: var(--cream) !important; margin: 4px 0; }
.score { font-size: 34px; text-align: center; font-family: Georgia, serif; color: var(--gold1); margin: 8px 0; }

@media (max-height: 460px) {
  .panel { padding: 12px 16px; }
  .menuPanel h1 { font-size: 30px; }
  .sub { margin: 0 0 8px; }
  .levels { margin-bottom: 6px; }
  .levels button { padding: 6px; }
  .row { margin: 4px 0; }
  .menuBtns { margin-top: 8px; }
  .menuBtns button { padding: 10px; }
  .ruleNote { display: none; }
  .overlay { padding-top: calc(8px + var(--sat)); padding-bottom: calc(8px + var(--sab)); }
}

/* telefon yatay: butonlar sagda dikey */
@media (orientation: landscape) and (max-height: 500px) {
  #app { flex-direction: row; padding: 0 0 0 var(--sal); }
  #mainCol { padding-top: var(--sat); padding-bottom: var(--sab); }
  #bar {
    flex-direction: column; width: calc(64px + var(--sar)); padding: calc(6px + var(--sat)) calc(8px + var(--sar)) calc(6px + var(--sab)) 8px;
    border-top: none; border-left: 1px solid #4a3a22; gap: 5px;
    background: linear-gradient(90deg, #1b2030, #0f121c);
  }
  .rb { flex: 1 1 0; max-width: none; width: 46px; height: auto; min-height: 30px; max-height: 44px; border-radius: 14px; padding: 0; }
  .rb b { display: none; }
  .rb svg { width: 20px; height: 20px; }
  #bMain { order: -1; min-width: 0; width: 52px; height: 52px; border-radius: 50%; padding: 0; flex: 0 0 auto; }
  #bMainText { display: none; }
  #bMain svg { width: 28px; height: 28px; }
  #bMainIcon:empty::after { content: '…'; font-size: 22px; }
}
