/* Randomizer: a native-feeling app with its own header, bottom tabs and settings sheet, in red
   and black like the table: black lacquer, red resin and white print. The 3D tables fill the stage; every motion respects reduced motion. */
:root {
  --bg: #f6f5f3; --card: #ffffff; --text: #121214; --muted: #5f5f68; --line: rgba(18, 18, 20, .14);
  --accent: #d21e2b; --accent-deep: #b3141f; --on-accent: #ffffff; --ink: #c4161f;
  --tile: linear-gradient(135deg, #c41a25, #4f070d);
  --glow: rgba(210, 30, 43, .16); --field: #ebeae7; --bar: rgba(248, 247, 245, .86);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b0b0d; --card: #18181b; --text: #f5f5f7; --muted: #a2a2ac; --line: rgba(235, 235, 245, .14);
  --ink: #ff5a64; --glow: rgba(210, 30, 43, .3); --field: #232327; --bar: rgba(11, 11, 13, .86);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.noscript { padding: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* The page is one screen: header, the open tab and the tab bar. */
.app {
  height: 100dvh; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto;
  background: radial-gradient(120% 50% at 50% -12%, var(--glow), transparent 62%) no-repeat, var(--bg);
}
.appbar { flex: none; padding: calc(env(safe-area-inset-top) + 2px) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
/* Inside OutApp: no top inset (the OutApp header covers it) and no own back link. */
:root[data-embed] .appbar { padding-top: 4px; }
:root[data-embed] .app { max-width: none; }
:root[data-embed] .standalone-only { display: none !important; }
.appbar-row { display: flex; align-items: center; gap: 4px; min-height: 44px; }
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding-right: 10px; color: var(--ink); text-decoration: none; font-size: 17px; }
.spacer { flex: 1; }
.app-title { display: flex; align-items: center; gap: 10px; margin: 0 4px 10px; font-size: 26px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; }
:root[data-embed] .app-title { font-size: 20px; margin-bottom: 8px; }
.app-tile { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--tile); color: var(--on-accent); flex: none; }
:root[data-embed] .app-tile { width: 28px; height: 28px; border-radius: 8px; }
:root[data-embed] .app-tile svg { width: 17px; height: 17px; }
.icon-button {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--text);
}
.icon-button.bordered { border: 1px solid var(--line); background: var(--card); }
.icon-button:active { transform: scale(.94); }

.panels { flex: 1; min-height: 0; display: flex; padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
.panel { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.panel[hidden] { display: none; }
.stage {
  position: relative; flex: 1; min-height: 220px; max-height: 620px; border-radius: 22px; overflow: hidden;
  background: radial-gradient(90% 80% at 40% 30%, #2a2b2f, #0b0b0d); isolation: isolate; touch-action: manipulation;
}
.table-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit; background: radial-gradient(ellipse 80% 75% at 50% 45%, transparent 58%, rgba(0, 0, 0, .34)); }
.stage.no-3d::before { content: attr(data-note); position: absolute; inset: auto 16px 16px; color: #e8f2e1; font-size: 15px; text-align: center; }
#panel-matches .stage { cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.label-short { display: none; }
.dice-total {
  position: absolute; top: 12px; right: 12px; z-index: 1; min-width: 44px; padding: 6px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, .28); color: #fff; font-weight: 800; font-size: 20px; text-align: center; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.dice-total[hidden] { display: none; }

.controls { flex: none; display: flex; align-items: center; gap: 10px; }
.stepper { display: flex; align-items: center; gap: 2px; border-radius: 14px; background: var(--field); padding: 2px; }
.stepper button { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; display: grid; place-items: center; }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper output { min-width: 26px; text-align: center; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.segmented { display: flex; gap: 2px; padding: 2px; border-radius: 14px; background: var(--field); }
.segmented button { min-width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; font-weight: 700; font-size: 17px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.primary {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 16px; white-space: nowrap;
  border: 0; border-radius: 15px; background: linear-gradient(180deg, var(--accent), var(--accent-deep)); color: var(--on-accent);
  font-weight: 700; font-size: 17px; box-shadow: 0 6px 18px rgba(190, 20, 30, .32), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .15s, filter .15s;
}
.primary:active { transform: translateY(1px) scale(.985); }
.primary:disabled { filter: saturate(.5) brightness(.96); cursor: default; }
.card-fields { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card-fields label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.card-fields input { min-width: 0; height: 46px; padding: 0 12px; border: 1px solid transparent; border-radius: 12px; background: var(--field); font-size: 16px; color: var(--text); }
.card-fields input:focus { outline: none; border-color: var(--ink); }

.result { flex: none; display: flex; align-items: center; gap: 10px; min-height: 46px; }
.result-text { flex: 1; margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.2px; line-height: 1.3; }
.result-text.pop { animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.share-button { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; font-size: 15px; }
.share-button[hidden] { display: none; }

/* Bottom tab bar: icons with labels, above the home indicator. */
.tabbar {
  flex: none; display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 8px;
  padding: 4px max(8px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 4px) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--line); background: var(--bar); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"] svg { stroke-width: 2.4; }

/* Sheets: full width from the bottom edge, content in a 520 px column on wide screens. */
.sheet {
  width: 100%; max-width: none; max-height: calc(100dvh - env(safe-area-inset-top) - 12px); margin: auto 0 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--card); color: var(--text); overflow-y: auto; overscroll-behavior: contain;
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet[open] { animation: rise .3s cubic-bezier(.2, .9, .3, 1); }
@keyframes rise { from { transform: translateY(48px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-body { display: grid; gap: 16px; max-width: 520px; margin: 0 auto; padding: 16px max(18px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
.sheet-body > * { min-width: 0; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 20px; letter-spacing: -.3px; }
.sheet-close { background: var(--field) !important; border-radius: 50% !important; }
.sheet-preview { width: 100%; aspect-ratio: 1; max-height: 40dvh; object-fit: contain; border-radius: 16px; background: #101214; }
.networks { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin: 0; padding: 0; list-style: none; }
.networks a, .networks button { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; min-height: 76px; padding: 4px 0; border: 0; border-radius: 12px; background: none; color: var(--text); text-decoration: none; font-size: 12px; cursor: pointer; }
.network-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--field); }
.network-icon svg { width: 22px; height: 22px; fill: currentColor; }
.share-actions { display: grid; }
.share-more { display: flex; align-items: center; gap: 12px; min-height: 46px; width: 100%; padding: 0 4px; border: 0; border-top: 1px solid var(--line); background: none; font-size: 16px; text-align: left; }
.share-more[hidden] { display: none; }
.sheet-status { margin: 0; min-height: 1.2em; color: var(--muted); font-size: 13px; }

/* Settings */
.pref h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.choice { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px; border-radius: 14px; background: var(--field); }
.choice button { min-height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 600; font-size: 15px; }
.choice button[aria-checked="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.pref-rows { display: grid; border-top: 1px solid var(--line); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-bottom: 1px solid var(--line); font-size: 17px; }
.toggle-row input { appearance: none; -webkit-appearance: none; position: relative; width: 51px; height: 31px; margin: 0; border-radius: 999px; background: var(--field); cursor: pointer; transition: background .2s; flex: none; }
.toggle-row input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); transition: transform .2s; }
.toggle-row input:checked { background: var(--accent); }
.toggle-row input:checked::after { transform: translateX(20px); }
.select-row { position: relative; gap: 12px; }
.select-value { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); }
.select-value::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
/* The native picker covers the whole row, so a tap anywhere opens it. */
.select-row select { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; font-size: 16px; }
.select-row:has(select:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 10px; }
.pref-about summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.pref-about p { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.pref-about a { color: var(--ink); }
.pref-warning { color: #c2410c !important; }
.pref-version { font-size: 13px !important; }

/* Narrow phones (320 px): labels stay, decorative icons go. */
@media (max-width: 359px) {
  .primary svg { display: none; }
  .controls { gap: 8px; }
  .label-long { display: none; }
  .label-short { display: inline; }
  .app-title { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Portrait only on phones (owner, 13 October 2026): a touch screen in landscape no taller than
   500 px is a phone; tablets and computers keep landscape. Inside OutApp its player covers this. */
.portrait-only { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  :root:not([data-embed]) .app, :root:not([data-embed]) dialog { visibility: hidden; }
  :root:not([data-embed]) .portrait-only { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; background: var(--bg); color: var(--text); text-align: center; }
  .portrait-only p { margin: 0; font-size: 17px; line-height: 1.3; font-weight: 600; }
  :root:not([lang^="ru"]):not([lang^="sr"]) .portrait-only p:not([lang="en"]), :root[lang^="ru"] .portrait-only p:not([lang="ru"]), :root[lang^="sr"] .portrait-only p:not([lang="sr-Latn"]) { display: none; }
  .portrait-only svg { transform: rotate(-90deg); animation: portrait-turn 1.4s ease-in-out .4s infinite alternate; }
}
@keyframes portrait-turn { to { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) { .portrait-only svg { animation: none; transform: none; } }
