:root {
  color-scheme: dark;
  --bg: #141311;
  --panel: #1f1d1b;
  --panel-active: #4a443e;
  --text: #ddd7d1;
  --muted: #b1aba5;
  --bar: #050505;
  --bar-border: #111111;
  --danger: #f08f87;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --panel-pad: clamp(8px, 1.7vh, 12px);
  --scramble-size: clamp(1.12rem, 2.7vh, 1.6rem);
  --clock-size: clamp(3.1rem, 17vh, 8.5rem);
  --control-height: clamp(38px, 5.2vh, 44px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next Condensed", "DIN Alternate", "Hiragino Kaku Gothic ProN", sans-serif;
}

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto 1fr auto;
  background: var(--bg);
}

.player {
  background: var(--panel);
  padding: max(var(--panel-pad), var(--safe-top)) 14px max(var(--panel-pad), var(--safe-bottom));
  display: grid;
  grid-template-rows: auto auto 1fr;
  align-items: start;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.player.top {
  transform: rotate(180deg);
}

.player.active {
  background: var(--panel-active);
  box-shadow: inset 0 0 0 3px #d4b27a, inset 0 0 42px rgba(212, 178, 122, 0.28);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 1rem;
}

.scramble {
  margin: clamp(30px, 5vh, 38px) 0 clamp(4px, 1vh, 8px);
  font-size: var(--scramble-size);
  line-height: 1.3;
  color: var(--muted);
  word-break: break-word;
  min-height: 2.9em;
}

.move-count {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 1rem;
}

.mini-opponent {
  position: absolute;
  top: 8px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  opacity: 0.85;
  transform: rotate(180deg);
}

.mini-clock {
  font-size: clamp(0.84rem, 2vh, 1rem);
  color: var(--text);
  letter-spacing: 0.02em;
}

.mini-moves {
  font-size: clamp(0.66rem, 1.5vh, 0.75rem);
  color: var(--muted);
}

.clock {
  align-self: center;
  justify-self: center;
  font-size: var(--clock-size);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: 0.03em;
}

.controls {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: var(--bar);
  border-top: 1px solid var(--bar-border);
  border-bottom: 1px solid var(--bar-border);
  padding: clamp(6px, 1.3vh, 10px) 12px;
}

#newScrambleBtn {
  justify-self: center;
  min-width: 140px;
}

.controls button:not(#newScrambleBtn) {
  min-width: 70px;
  font-size: 0.86rem;
}

input,
button {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}

input {
  width: 52px;
  font-size: 1.05rem;
  text-align: right;
  padding: 2px 0;
}

button {
  height: var(--control-height);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #302c28;
  color: #d1cbc5;
  border: 1px solid #3c3733;
  padding: 0 10px;
}

button:active {
  background: #3c3733;
}

button.primary {
  font-size: 0.86rem;
  letter-spacing: 0.01em;
}

.status {
  margin: 0;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: #141414;
  color: var(--muted);
  font-size: clamp(0.74rem, 1.8vh, 0.82rem);
  text-align: center;
}

.status.end {
  color: var(--danger);
}

.settings-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  align-items: end;
  z-index: 20;
}

.settings-sheet.hidden {
  display: none;
}

.sheet-panel {
  background: #121110;
  border-top: 1px solid #2a2724;
  border-radius: 16px 16px 0 0;
  padding: 12px 14px calc(14px + var(--safe-bottom));
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.setting-block {
  margin-top: 12px;
}

.setting-block label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.toggle-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0 !important;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 10px;
  align-items: center;
}

.setting-row input[type="number"] {
  width: 72px;
  background: #0b0a0a;
  border: 1px solid #2a2724;
  border-radius: 8px;
  padding: 6px 8px;
}

.setting-row input[type="range"] {
  width: 100%;
}

#applySettingsBtn {
  margin-top: 14px;
  width: 100%;
}

@media (max-height: 760px) {
  :root {
    --scramble-size: clamp(0.98rem, 2.2vh, 1.18rem);
    --clock-size: clamp(2.7rem, 13vh, 5.2rem);
  }

  .scramble {
    min-height: 2.2em;
  }

  #newScrambleBtn {
    min-width: 124px;
  }

  .controls button:not(#newScrambleBtn) {
    min-width: 58px;
  }
}

@media (min-width: 900px) {
  .app {
    max-width: 540px;
    margin: 0 auto;
    border-left: 1px solid #3b3734;
    border-right: 1px solid #3b3734;
  }
}
