/* theme.css is the shared look of the game pages: the tokens, the reset,
   the components and the layout docs/design/ui.md describes. A page loads
   it first and may redeclare tokens on its own :root (a skin); it does not
   restyle the components. No font and no file is loaded from outside: the
   pages are embedded and serve offline (web/embed.go). */

:root {
  color-scheme: dark;

  --bg: #0f2622;
  --panel: #143029;
  --panel-2: #1a3a32;
  --line: #2f4a44;
  --accent: #e3a72f;
  --accent-2: #f0bf5a;
  --accent-ink: #1c1406;
  --win: #4cd48a;
  --lose: #ff5c6a;
  --text: #e6efec;
  --muted: #9db8b1;
  --focus: #8fd3ff;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-32: 32px;
  --lh: 1.5;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);

  --dur-fast: 150ms;
  --dur: 300ms;
  --dur-slow: 1200ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---- reset ------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
h1,
h2,
h3,
p,
ul,
ol,
figure,
dialog {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

html {
  font-family: var(--font);
  font-size: var(--fs-16);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3 {
  line-height: 1.2;
}

.num {
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.muted {
  color: var(--muted);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- layout ----------------------------------------------------------- */

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4);
  display: grid;
  gap: var(--space-5);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "header"
    "board"
    "side";
}

.app > header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.app > header h1 {
  font-size: var(--fs-20);
  font-weight: 700;
}

.board {
  grid-area: board;
  min-width: 0;
}

.side {
  grid-area: side;
  display: grid;
  gap: var(--space-4);
  align-content: start;
}

.balance {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.balance .label {
  color: var(--muted);
  font-size: var(--fs-13);
}

.balance .amount {
  font-size: var(--fs-24);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  transition: transform var(--dur) var(--ease);
}

.balance .amount.pulse {
  animation: pulse var(--dur) var(--ease);
}

.closing .balance {
  color: var(--muted);
}

@keyframes pulse {
  50% {
    transform: scale(1.04);
  }
}

/* ---- panel ------------------------------------------------------------ */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

.panel h2 {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--muted);
  margin-bottom: var(--space-3);
}

/* ---- buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font-size: var(--fs-14);
  font-weight: 500;
  transition:
    border-color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) ease-out,
    opacity var(--dur-fast) var(--ease);
}

.btn:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  width: 100%;
  min-height: 48px;
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--fs-16);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-2);
  border-color: transparent;
}

.btn-primary.busy {
  pointer-events: none;
  opacity: 0.5;
}

/* ---- field and presets ------------------------------------------------ */

.field {
  display: grid;
  gap: var(--space-1);
}

.field label {
  color: var(--muted);
  font-size: var(--fs-13);
}

.field .input {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  transition: border-color var(--dur-fast) var(--ease);
}

.field .input:focus-within {
  border-color: var(--accent-2);
}

.field input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  background: transparent;
  font-size: var(--fs-16);
  font-variant-numeric: tabular-nums;
}

.field input:focus {
  outline: none;
}

.field .currency {
  padding-right: var(--space-3);
  color: var(--muted);
  font-size: var(--fs-13);
}

.field.invalid .input {
  border-color: var(--lose);
}

.field .reason {
  color: var(--lose);
  font-size: var(--fs-13);
  min-height: 1.2em;
}

.presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
}

.presets .btn {
  padding-inline: var(--space-2);
}

.panel.bet {
  display: grid;
  gap: var(--space-3);
}

/* ---- toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translate(-50%, 0);
  z-index: 20;
  max-width: min(480px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  animation: toast-in var(--dur) var(--ease);
}

.toast.win {
  color: var(--win);
}

.toast.lose,
.toast.error {
  color: var(--lose);
}

/* The "Init session" button a page without a token puts on its toast
   (sdk/ui.js withInitSession): next to the text, a link styled as a button. */
.toast .btn {
  margin-left: var(--space-3);
  color: var(--text);
  text-decoration: none;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, var(--space-2));
  }
}

/* ---- history ---------------------------------------------------------- */

.history {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: var(--space-1);
}

.history li {
  flex: 0 0 auto;
}

.history .chip {
  min-width: 44px;
  min-height: 32px;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  font-size: var(--fs-13);
  font-variant-numeric: tabular-nums;
  animation: chip-in var(--dur) var(--ease);
}

.history .chip.win {
  color: var(--win);
  border-color: var(--win);
}

@keyframes chip-in {
  from {
    opacity: 0;
    transform: translateY(var(--space-1));
  }
}

/* ---- fairness --------------------------------------------------------- */

.fair {
  display: none;
}

.fair.open {
  display: grid;
  gap: var(--space-3);
}

.fair dl {
  display: grid;
  gap: var(--space-1);
}

.fair dt {
  color: var(--muted);
  font-size: var(--fs-13);
}

.fair dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  word-break: break-all;
}

.fair .mark {
  font-weight: 600;
}

.fair .mark.ok {
  color: var(--win);
}

.fair .mark.bad {
  color: var(--lose);
}

.fair .mark.pending {
  color: var(--muted);
}

.fair .mark.partial {
  color: var(--accent-2);
}

/* A backend without seeds or proofs: the panel only says so. */
.fair .fair-off {
  margin: 0;
  color: var(--muted);
}

/* ---- modal ------------------------------------------------------------ */

.modal {
  width: min(560px, 92vw);
  max-height: 85vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur) var(--ease);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.modal .panel {
  border: 0;
  box-shadow: none;
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.modal table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.modal th,
.modal td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.modal th:first-child,
.modal td:first-child {
  text-align: left;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---- breakpoints ------------------------------------------------------ */

@media (min-width: 768px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-areas:
      "header header"
      "board side";
  }
}

@media (max-width: 767px) {
  .btn,
  .history .chip {
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .app {
    padding-bottom: 220px;
  }

  .panel.bet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    box-shadow: var(--shadow-lg);
  }

  .presets {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .balance .label {
    display: none;
  }
}

/* ---- motion ----------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
