:root {
  --bg: #edf3f6;
  --card: #f7fbfd;
  --line: #c8d7dd;
  --text: #19384a;
  --muted: #688395;
  --teal: #2ca7b5;
  --teal-dark: #1b899a;
  --purple: #7d39f6;
  --purple-soft: #efe6ff;
  --green: #80d94c;
  --amber: #f7b23b;
  --red: #ff5e67;
  --wood-1: #d7bb8d;
  --wood-2: #c9ab78;
  --wood-3: #b78f5b;
  --wood-line: #8a6a43;
  --hole: #f1dfbf;
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  padding: 8px 10px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 10%, rgba(111,34,237,.055), transparent 25%),
              radial-gradient(circle at 90% 85%, rgba(35,150,165,.07), transparent 28%),
              linear-gradient(180deg, #f3f7f9 0%, #ebf1f5 100%);
}

button { font: inherit; }

.game-app {
  width: min(100%, 1140px);
  margin: 0 auto;
  padding: 8px;
  border: 1px solid #e0eaed;
  border-radius: 22px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 18px 54px rgba(34,64,75,.10);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, min(700px, calc(100vh - 44px))) minmax(310px, 360px);
  justify-content: center;
  gap: 10px;
  align-items: start;
}

.game-column {
  width: 100%;
  max-width: min(700px, calc(100vh - 44px));
  min-width: 0;
}

.control-column {
  min-width: 0;
}

.board-frame,
.control-panel,
.status-card,
.meti-panel,
.player-colors {
  background: rgba(255,255,255,0.78);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.85) inset;
}

.board-frame {
  padding: 12px;
}

.kulami-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr)); 
  gap: 0;
  width: 100%; 
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 8px; 
  border-radius: 28px;
  background: linear-gradient(145deg, #c9aa78, #ecd4aa 35%, #c19a67 100%);
  border: 7px solid #a47d4f;
  box-shadow:
    inset 0 0 0 3px rgba(255,255,255,0.32),
    inset 0 0 22px rgba(112,74,24,0.18),
    0 18px 32px rgba(64, 50, 26, 0.12);
}

.kulami-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: none;
  border-radius: 0;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  background: transparent;
}

.kulami-cell:disabled {
  cursor: default;
}

.tile-surface {
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, rgba(248,232,198,.95), rgba(233,210,165,.98));
  border: 2px solid var(--wood-line);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
}

.kulami-cell .hole {
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #cfb184 0%, #bd9d6d 58%, #a8885c 100%);
  box-shadow: inset 0 0 0 2px rgba(122,92,49,0.35);
}

.kulami-cell.legal .hole {
  box-shadow: inset 0 0 0 2px rgba(122,92,49,0.35);
}

.kulami-cell.restricted .tile-surface::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 10px;
  border: 2px dashed rgba(125,57,246,0.25);
}

.marble {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  box-shadow: inset -10px -12px 18px rgba(0,0,0,0.22), inset 10px 10px 14px rgba(255,255,255,0.25), 0 4px 6px rgba(0,0,0,0.15);
}

.kulami-cell.recent-move .marble::after {
  content: '★';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 10px;
  line-height: 1;
  color: #fff9df;
  background: radial-gradient(circle at 30% 28%, #ffe78d 0%, #f6ba35 58%, #d98c00 100%);
  border: 2px solid rgba(255,255,255,.88);
  box-shadow: 0 2px 7px rgba(81,55,18,.30);
  text-shadow: 0 1px 2px rgba(90,55,0,.34);
  z-index: 5;
}

.kulami-cell.latest-move .marble::after {
  width: 20px;
  height: 20px;
  font-size: 11px;
  box-shadow: 0 2px 8px rgba(81,55,18,.34), 0 0 0 2px rgba(255,218,89,.22);
}

.move-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(92, 92, 92, .72);
  box-shadow: 0 0 0 4px rgba(255,255,255,.10), 0 1px 3px rgba(0,0,0,.20);
  pointer-events: none;
  z-index: 4;
}

.marble.player1 {
  background: radial-gradient(circle at 28% 28%, #7fe4ef 0%, #46c2cf 38%, #1795a6 100%);
}

.marble.player2 {
  background: radial-gradient(circle at 28% 28%, #d2a6ff 0%, #9e62ff 40%, #6f31db 100%);
}

.control-column {
  height: min(700px, calc(100vh - 44px));
  max-height: min(700px, calc(100vh - 44px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 7px;
  overflow: hidden;
}

.control-panel, .status-card, .meti-panel, .player-colors {
  padding: 8px;
}

.setting-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px;
  margin-bottom: 6px;
  background: rgba(252,254,255,0.72);
}
.setting-block:last-child { margin-bottom: 0; }
.setting-label {
  display: block;
  font-size: .72rem;
  font-weight: 850;
  color: #36566a;
  margin-bottom: 6px;
}
.setting-help {
  display: block;
  color: var(--muted);
  font-size: .66rem;
  margin-top: -2px;
}
.mode-grid,
.difficulty-grid {
  display: grid;
  gap: 6px;
}
.mode-grid { grid-template-columns: repeat(2, 1fr); }
.difficulty-grid { grid-template-columns: repeat(3, 1fr); }
.mode-button,
.difficulty-button,
.new-game-button,
.primary-button,
.secondary-button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbfdfe;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  transition: .18s ease;
}
.mode-button { min-height: 36px; padding: 5px 8px; }
.difficulty-button { min-height: 50px; padding: 5px 3px; }
.mode-button.active {
  background: linear-gradient(135deg, #9145ff, #6f22ea);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(111,34,234,.20);
}
.difficulty-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
}
.difficulty-button strong { font-size: .69rem; line-height: 1.15; }
.difficulty-button.active {
  border-color: #9657ff;
  box-shadow: 0 0 0 3px rgba(149,87,255,0.10) inset;
  background: #fff;
}
.level-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 3px solid rgba(255,255,255,.82);
  box-shadow: 0 4px 10px rgba(27,52,66,.14);
}
.easy-dot { background: var(--green); }
.medium-dot { background: var(--amber); }
.hard-dot { background: var(--red); }

.compact-toggle-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.toggle-switch {
  width: 42px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: #d9e5ea;
  padding: 3px;
  position: relative;
  cursor: pointer;
}
.toggle-switch.active { background: var(--teal); }
.toggle-knob {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  transition: transform .18s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.16);
}
.toggle-switch.active .toggle-knob { transform: translateX(18px); }

.new-game-button,
.primary-button,
.secondary-button {
  min-height: 38px;
  padding: 0 14px;
}
.new-game-button,
.primary-button {
  background: linear-gradient(135deg, #31abb7, #198ea1);
  color: #fff;
  border-color: transparent;
}
.secondary-button { background: #eef4f7; }

.status-card { display: grid; gap: 5px; }
.turn-info {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.turn-piece,
.mini-piece {
  display: inline-block;
  border-radius: 50%;
}
.turn-piece {
  width: 34px;
  height: 34px;
  box-shadow: inset -8px -10px 12px rgba(0,0,0,0.22), inset 8px 8px 10px rgba(255,255,255,.25);
}
.mini-piece {
  width: 17px;
  height: 17px;
  margin-right: 6px;
  vertical-align: middle;
  box-shadow: inset -4px -5px 8px rgba(0,0,0,0.22), inset 5px 5px 7px rgba(255,255,255,.25);
}
.player-one-piece { background: radial-gradient(circle at 28% 28%, #7fe4ef 0%, #46c2cf 38%, #1795a6 100%); }
.player-two-piece { background: radial-gradient(circle at 28% 28%, #d2a6ff 0%, #9e62ff 40%, #6f31db 100%); }
.small-label {
  display: block;
  font-size: .68rem;
  color: #5b7281;
}
#turnText { font-size: .88rem; }
.move-info {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #456576;
}
.move-badge {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--teal);
  flex: 0 0 auto;
}

.meti-panel {
  min-height: 0;
  display: grid;
  grid-template-columns: 64px minmax(0,1fr);
  gap: 7px;
  align-items: center;
  overflow: hidden;
}
.meti-avatar,
.result-meti-avatar {
  width: 64px;
  min-width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto;
}
.meti-image,
.result-meti-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.10));
}
.meti-bubble {
  background: #2f3892;
  color: #fff;
  border-radius: 15px;
  padding: 10px 12px;
  position: relative;
}
.meti-bubble::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  border: 12px solid transparent;
  border-right-color: #2f3892;
}
.meti-bubble strong {
  display: block;
  font-size: .88rem;
  margin-bottom: 3px;
}
.meti-bubble p { margin: 0; line-height: 1.28; font-size: .78rem; }

.player-colors {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.player-color-card {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(252,254,255,0.7);
}
.player-color-card span { display: block; color: #667f90; margin-bottom: 2px; font-size:.78rem; }
.player-color-card strong { display: block; font-size: .84rem; margin-bottom: 4px; }
.player-color-card b { color: #31586f; font-size:.78rem; }

.stock-text {
  display:block;
  margin-top:2px;
  color:#7b8d98;
  font-size:.66rem;
  font-weight:700;
}

.result-score-card {
  min-width:180px;
  padding:10px 12px;
  border:1px solid var(--line);
  border-radius:14px;
  background:#f8fbfc;
}
.result-score-card strong {
  display:block;
  color:#274d62;
  font-size:.94rem;
}
.result-score-card small {
  display:block;
  margin-top:4px;
  color:#6b7e89;
  font-size:.75rem;
  font-weight:700;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 40;
}
.modal.show { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(19,29,35,0.58);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(92vw, 520px);
  margin: 7vh auto 0;
  background: #fff;
  border-radius: 28px;
  padding: 30px 28px;
  text-align: center;
  box-shadow: 0 26px 60px rgba(0,0,0,0.22);
}
.result-eyebrow {
  color: var(--teal-dark);
  font-weight: 800;
  letter-spacing: .12em;
  margin: 12px 0 8px;
}
.result-card h2 { margin: 0 0 10px; font-size: 2rem; }
.result-score {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-weight: 800;
  color: #30576a;
  margin-top: 14px;
  flex-wrap: wrap;
}
.result-meti-text {
  background: #f1f6f9;
  border-radius: 16px;
  padding: 14px 16px;
  margin-top: 18px;
  color: #35566a;
}
.modal-actions {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Masaüstü görünüm tam orijinal yerinde kalır (Tahta solda, panel sağda) */
@media (min-width: 851px) {
  .workspace {
    grid-template-columns: minmax(0, min(700px, calc(100vh - 44px))) minmax(310px, 360px);
    display: grid;
    align-items: start;
  }

  .game-column {
    order: 1;
    max-width: min(700px, calc(100vh - 44px));
  }

  .control-column {
    order: 2;
    display: grid;
    height: min(700px, calc(100vh - 44px));
    max-height: min(700px, calc(100vh - 44px));
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    overflow: hidden;
  }
}

/* Mobil görünüm: Oyun tahtası üstte, sadece ayarlar paneli tahtanın hemen altında, kartlar yan yana */
@media (max-width: 850px) {
  .workspace { 
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  
  .game-column { 
    order: 1;
    max-width: none; 
  }

  .control-column {
    order: 2;
    display: flex;
    flex-direction: column;
    height: auto;
    max-height: none;
    overflow: visible;
    gap: 7px;
  }

  /* Oyun ayarları paneli (.control-panel) mobil akışta en üste (tahtanın hemen altına) taşınır */
  .control-panel {
    order: -1;
  }

  /* Oyuncu kartları yan yana kalmaya devam eder */
  .player-colors {
    grid-template-columns: repeat(2, 1fr);
  }

  .difficulty-grid { grid-template-columns: repeat(3, 1fr); }
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
  .meti-panel { grid-template-columns: 64px minmax(0,1fr); }
  .meti-bubble::before { display: block; }
}

@media (max-width: 520px) {
  body { padding: 4px; }
  .game-app { width: 100%; padding: 9px; border-radius: 20px; }
  .board-frame { padding: 10px; }
  .kulami-board { width: 100%; padding: 10px; border-width: 5px; }
  .difficulty-grid { grid-template-columns: 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .meti-panel { grid-template-columns: 1fr; }
  .meti-bubble::before { display: none; }
  .meti-bubble { border-radius: 18px; }
}