@import url('https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic:wght@400;700;900&family=Yuji+Mai&display=swap');

/* --- Design Tokens --- */
:root {
  --bg: #1a0e0a;
  --panel: #1e1209;
  --gold: #d4a24e;
  --gold-bright: #f0c060;
  --gold-dark: #8a6830;
  --red: #c43030;
  --red-bright: #ff4444;
  --neon-red: #ff2020;
  --neon-orange: #ff8c00;
  --cream: #f5e6d0;
  --cream-dim: #a89880;
  --wood: #3d2818;
  --wood-light: #5a3d28;
}

/* --- Reset & Base --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100dvh;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--cream);
  font-family: 'Zen Maru Gothic', sans-serif;
  display: flex;
  flex-direction: column;
  font-size: 10px;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0 auto;
  width: 100%;
  padding: 2px;
}

/* --- Shared Components --- */
.btn {
  background: var(--wood);
  border: 1px solid var(--gold-dark);
  color: var(--gold);
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  touch-action: manipulation;
}
.btn:active { transform: scale(.95); background: var(--gold-dark); color: var(--bg); }
.btn-r { border-color: var(--red); color: var(--red-bright); }
.btn-g { background: var(--gold-dark); color: var(--bg); font-weight: 700; }

.board-flex {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.board-flex canvas {
  border: 2px solid var(--wood-light);
  border-radius: 3px;
  background: #0a0604;
  touch-action: none;
  display: block;
}

/* Noren (curtain) decoration */
.noren-mini {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}
.noren-mini i {
  width: 20px;
  height: 8px;
  background: linear-gradient(180deg, var(--red), #8a2020);
  border-radius: 0 0 4px 4px;
  opacity: .8;
  display: block;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
}

/* --- Header --- */
.hdr {
  text-align: center;
  padding: 4px 0 2px;
  flex-shrink: 0;
}
.hdr h1 {
  font-family: 'Yuji Mai', serif;
  font-size: 18px;
  color: var(--gold-bright);
  letter-spacing: .08em;
  text-shadow: 0 0 10px rgba(212, 162, 78, .3);
}
.hdr .noren-mini { margin-bottom: 2px; }

/* --- Start Screen --- */
.start {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  text-align: center;
}
.start-noren {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 4px;
}
.start-noren i {
  width: 36px;
  height: 50px;
  background: linear-gradient(180deg, var(--red) 0%, #8a2020 100%);
  border-radius: 0 0 8px 8px;
  display: block;
  opacity: .85;
  box-shadow: 0 4px 8px rgba(0, 0, 0, .3);
}
.start-title {
  font-family: 'Yuji Mai', serif;
  font-size: 36px;
  color: var(--gold-bright);
  letter-spacing: .12em;
  text-shadow: 0 0 30px rgba(212, 162, 78, .5), 0 3px 6px rgba(0, 0, 0, .6);
  line-height: 1.2;
}
.start-subtitle { font-size: 13px; color: var(--cream-dim); margin-top: 2px; }
.start-lantern { font-size: 28px; margin: 4px 0; }
.start-desc {
  font-size: 14px;
  color: var(--cream);
  line-height: 1.6;
  background: rgba(212, 162, 78, .06);
  border: 1px solid var(--wood-light);
  border-radius: 10px;
  padding: 12px 16px;
  max-width: 320px;
}
.start .sb {
  padding: 16px 36px;
  font-size: 17px;
  border-radius: 12px;
  font-family: 'Yuji Mai', serif;
  letter-spacing: .05em;
  width: 100%;
  max-width: 280px;
}
.start .sb-main {
  background: linear-gradient(135deg, var(--red), #8a2020);
  border: 2px solid var(--gold-dark);
  color: var(--gold-bright);
  font-size: 18px;
  box-shadow: 0 4px 15px rgba(196, 48, 48, .3);
}
.start .sb-main:active { background: var(--red); transform: scale(.97); }
.start .sb-sub {
  background: var(--wood);
  border: 1px solid var(--gold-dark);
  color: var(--gold);
  font-size: 15px;
}

/* --- Tetris Phase --- */
.t-info {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px 0;
}
.t-info-item {
  background: var(--panel);
  border: 1px solid var(--wood-light);
  border-radius: 4px;
  padding: 2px 6px;
  text-align: center;
}
.t-info-item .lb { font-size: 10px; color: var(--cream-dim); }
.t-info-item .vl { font-size: 14px; font-weight: 900; color: var(--gold-bright); }

/* Control strip (shared between tetris & izakaya) */
.t-strip, .iz-strip {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  width: 100%;
}
.t-strip { padding: 3px 0; max-width: 360px; margin: 0 auto; }
.iz-strip { padding: 0; }

.t-strip .mv, .iz-strip .mv {
  flex: 1;
  padding: 14px 0;
  border-radius: 8px;
  background: var(--panel);
  border: 2px solid var(--wood-light);
  color: var(--cream);
  font-size: 24px;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  text-align: center;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.t-strip .mv:active, .iz-strip .mv:active {
  background: var(--wood);
  border-color: var(--gold);
}

.t-strip .rot, .iz-strip .rot {
  flex: 1.2;
  padding: 14px 0;
  border-radius: 8px;
  background: var(--gold-dark);
  border: 2px solid var(--gold-bright);
  color: var(--bg);
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  text-align: center;
  font-weight: 700;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.t-strip .rot:active, .iz-strip .rot:active {
  background: var(--gold-bright);
}

.t-hint {
  font-size: 10px;
  color: var(--cream-dim);
  text-align: center;
  margin-top: 2px;
}

/* --- Izakaya Phase --- */
.iz-main {
  flex: 1;
  display: flex;
  gap: 4px;
  min-height: 0;
  overflow: hidden;
}
.iz-board-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  max-width: min(62%, 400px);
}
.iz-side {
  width: 36%;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 2px;
}

/* Side panel title */
.side-title { text-align: center; padding: 6px 0 3px; }
.side-title-text {
  font-family: 'Yuji Mai', serif;
  font-size: 18px;
  color: var(--gold-bright);
  letter-spacing: .05em;
  line-height: 1.2;
  text-shadow: 0 0 10px rgba(212, 162, 78, .4);
}

/* Side panel boxes */
.side-box {
  background: var(--panel);
  border: 1px solid var(--wood-light);
  border-radius: 6px;
  padding: 6px;
  text-align: center;
}
.side-stock .lbl { font-size: 11px; color: var(--cream-dim); }
.side-stock .num { font-size: 32px; font-weight: 900; color: var(--gold-bright); line-height: 1; }
.side-cd .lbl { font-size: 10px; color: var(--cream-dim); }
.side-cd { font-family: 'Yuji Mai', serif; font-size: 34px; font-weight: 900; line-height: 1; }

/* Card area */
.side-card {
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.side-draw {
  padding: 10px 4px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--red), #8a2020);
  border: 1px solid var(--gold-dark);
  color: var(--gold-bright);
  font-family: 'Yuji Mai', serif;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  width: 100%;
  text-align: center;
}
.side-draw:active { transform: scale(.95); }
.side-draw.off { opacity: .4; pointer-events: none; }

/* Drawn card badge */
.drawn-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 8px;
  border: 2px solid var(--wood-light);
  background: rgba(0, 0, 0, .3);
  width: 100%;
}
.drawn-badge.jk { border-color: var(--red); background: rgba(196, 48, 48, .15); }
.drawn-badge.ace { border-color: var(--gold); background: rgba(212, 162, 78, .15); }
.drawn-badge.piece { background: rgba(255, 255, 255, .05); }
.drawn-name { font-size: 16px; font-weight: 900; }
.drawn-lbl { font-size: 10px; color: var(--cream-dim); }

/* Piece selection grid */
.side-psel { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.side-po {
  width: 36px;
  height: 36px;
  background: var(--bg);
  border: 2px solid var(--wood-light);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.side-po:active { border-color: var(--gold-bright); }

/* Stock button */
.side-stock-btn {
  width: 100%;
  padding: 10px 4px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  border: 2px solid var(--gold-dark);
  background: var(--panel);
  color: var(--cream);
  touch-action: manipulation;
  text-align: center;
  line-height: 1.3;
}
.side-stock-btn:active {
  border-color: var(--gold-bright);
  background: rgba(212, 162, 78, .2);
  transform: scale(.96);
}
.side-stock-btn .pl { color: var(--gold-bright); font-size: 11px; }

/* Side sections */
.side-section {
  background: var(--panel);
  border: 1px solid var(--wood-light);
  border-radius: 6px;
  padding: 5px;
}
.side-section-title {
  font-family: 'Yuji Mai', serif;
  font-size: 11px;
  color: var(--gold);
  text-align: center;
  margin-bottom: 3px;
}

/* Card pool */
.cp { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin: 4px 0; }
.pc {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, .1);
  cursor: pointer;
  touch-action: manipulation;
  transition: all .1s;
  padding: 2px;
}
.pc.a { background: rgba(245, 230, 208, .15); color: var(--cream); }
.pc.a:active { transform: scale(.9); opacity: .7; }
.pc.rm {
  background: rgba(196, 48, 48, .15);
  color: var(--red-bright);
  border-color: rgba(196, 48, 48, .4);
  cursor: pointer;
  opacity: .4;
}
.pc.rm svg { filter: grayscale(1); }
.pc.rm:active { transform: scale(.9); }
.cp-hint { font-size: 10px; color: var(--gold-dark); text-align: center; margin-top: 2px; }

/* Mode tabs */
.mt { display: flex; gap: 4px; margin-bottom: 4px; }
.mtab {
  flex: 1;
  padding: 8px 4px;
  background: var(--bg);
  border: 2px solid var(--wood-light);
  color: var(--cream-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  border-radius: 5px;
  touch-action: manipulation;
  font-weight: 700;
}
.mtab.on { background: var(--wood); color: var(--gold); border-color: var(--gold-dark); }
.rdesc { font-size: 11px; color: var(--cream-dim); margin: 2px 0; }

/* --- Overlays --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s;
}
.overlay.show { opacity: 1; pointer-events: all; }
.overlay-box {
  text-align: center;
  padding: 20px;
  background: var(--panel);
  border-radius: 14px;
  max-width: 88vw;
}
.overlay-box h2 { font-family: 'Yuji Mai', serif; font-size: 22px; margin-bottom: 8px; }
.overlay-box p { color: var(--cream); margin-bottom: 8px; font-size: 13px; }
.prize {
  font-size: 26px;
  font-weight: 900;
  color: var(--neon-red);
  text-shadow: 0 0 15px rgba(255, 32, 32, .5);
  animation: prize-pulse .5s ease infinite alternate;
}
@keyframes prize-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}