/* CritDice web — styling modelled on the original Android app (dark Material theme). */

:root {
  color-scheme: dark;
  --bg: #303030;              /* window background (Theme.AppCompat dark) */
  --bg-dialog: #303030;       /* dialog / fragment background */
  --primary: #515151;         /* toolbar */
  --primary-dark: #212121;    /* status bar */
  --highlight: #2196F3;       /* accent (FAB, links) */
  --highlight-dark: #0D47A1;
  --highlight-shadow: #1E7AC3;
  --drawer-bg: #313131;
  --grey: #9E9E9E;
  --grey200: #EEEEEE;
  --grey300: #E0E0E0;
  --grey600: #757575;
  --grey700: #616161;
  --grey800: #424242;
  --grey900: #212121;
  --disabled-grey: rgba(158, 158, 158, 0.3);
  --text: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-bright: rgba(255, 255, 255, 0.87);   /* #DDFFFFFF */
  --text-normal: rgba(255, 255, 255, 0.67);   /* #AAFFFFFF */
  --text-dim: rgba(255, 255, 255, 0.38);      /* dropped/rerolled dice */
  --toolbar-h: 56px;
  --font: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;

  --die-d100: #607D8B; --die-d20: #2196F3; --die-d12: #009688; --die-d10: #8BC34A; --die-d8: #FFC107;
  --die-d6: #FF5722; --die-d4: #B71C1C; --die-d3: #673AB7; --die-d2: #3F51B5; --die-dF: #795548; --die-dN: #9E9E9E;

  --size-input: 38px;
  --size-hint: 20px;
  --size-die: 32px;
  --size-die-small: 28px;
  --size-num: 36px;
  --size-roll: 44px;
  --size-total: 128px;
  --content-max: 720px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--highlight); outline-offset: -2px; }
.icon { width: 24px; height: 24px; vertical-align: middle; }
[hidden] { display: none !important; }

/* Layout ------------------------------------------------------------------ */

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
}
.toolbar {
  flex: 0 0 auto;
  height: var(--toolbar-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 5;
}
.main-toolbar { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.icon-btn {
  width: 56px; height: 56px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); flex: 0 0 auto;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.12); }
.toolbar-title { flex: 1 1 auto; font-size: 20px; font-weight: 500; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-actions { display: flex; align-items: center; height: 100%; }
.toolbar-action { border: 0; background: transparent; height: 100%; padding: 0 16px; font-size: 14px; font-weight: 500; letter-spacing: 0.5px; color: var(--text); }
.toolbar-action:active { background: rgba(255, 255, 255, 0.12); }

.tabs { position: relative; display: flex; height: 100%; align-items: stretch; }
.tab { width: 64px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--text); opacity: 0.6; transition: opacity 0.15s; }
.tab.is-selected { opacity: 1; }
.tab:active { background: rgba(255, 255, 255, 0.12); }
.tab-img { width: 24px; height: 24px; display: block; }
.tab-indicator { position: absolute; left: 0; bottom: 0; height: 4px; width: 64px; background: var(--grey200); transition: none; pointer-events: none; }

.pages {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.pages::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.page-keypad { align-items: center; }
.page-list { overflow-y: auto; align-items: center; }
.page-list .list { width: 100%; max-width: var(--content-max); padding: 4px 4px 96px; }

/* Keypad ------------------------------------------------------------------ */

.keypad {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--content-max);
  height: 100%;
  padding: 0 0 env(safe-area-inset-bottom);
  user-select: none;
}
.krow { display: flex; align-items: stretch; min-height: 0; }
.krow-input { min-height: 60px; margin: 4px 0; }
.keypad-advanced .krow-input { margin-bottom: 0; }
.krow-hint { min-height: 34px; }
.row-narrow { margin-left: 50px; margin-right: 50px; }
.row-gap-top { margin-top: 4px; }
.kinput {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: flex-end;
  margin-left: 8px; font-size: var(--size-input); --input-size: var(--size-input); color: var(--text);
  white-space: nowrap; overflow: hidden; text-align: right; line-height: 1.2; align-self: stretch;
}
.kdel { flex: 0 0 64px; border: 0; background: transparent; color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.kdel:active { background: var(--grey900); }
.khint {
  flex: 1 1 auto; margin: 0 16px 4px 4px; font-size: var(--size-hint); line-height: 1.15; color: var(--text); text-align: right;
  min-height: 34px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.key {
  flex: 1 1 0; min-width: 0; border: 0; border-radius: 0; margin: 0; padding: 0;
  background: transparent; color: var(--text-normal); font-size: var(--size-num); font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
  transition: opacity 0.1s;
}
.key:disabled { cursor: default; }
.key.is-disabled { opacity: 0.3; }
.key-num:not(:disabled):active { background: var(--grey900); }
.key-die { color: var(--text-bright); font-size: var(--size-die); background: var(--die-color, var(--grey)); }
.key-die:not(:disabled):active { filter: brightness(0.8); }
.key-small { font-size: var(--size-die-small) !important; }
.key-mod { font-size: var(--size-die-small); }
.die-d100 { --die-color: var(--die-d100); } .die-d20 { --die-color: var(--die-d20); } .die-d12 { --die-color: var(--die-d12); }
.die-d10 { --die-color: var(--die-d10); } .die-d8 { --die-color: var(--die-d8); } .die-d6 { --die-color: var(--die-d6); }
.die-d4 { --die-color: var(--die-d4); } .die-d3 { --die-color: var(--die-d3); } .die-d2 { --die-color: var(--die-d2); }
.die-dF { --die-color: var(--die-dF); } .die-dN { --die-color: var(--die-dN); }
.krow-actions { min-height: 56px; }
.key-roll { color: var(--text-bright); font-size: var(--size-roll); background: var(--key-color, var(--grey)); }
.key-roll.is-disabled { background: var(--grey); }
.key-roll:not(:disabled):active { filter: brightness(0.8); }
.key-icon { background: var(--disabled-grey); color: var(--text); }
.key-icon .icon { opacity: 0.2; }
.key-icon.is-colored { background: var(--key-color); }
.key-icon:not(.is-disabled) .icon { opacity: 0.87; }
.key-icon.is-disabled { opacity: 1; }
.key-icon:not(:disabled):active { filter: brightness(0.8); }

/* Lists / cards ----------------------------------------------------------- */

.group-header {
  display: flex; align-items: center; width: 100%; border: 0; background: transparent; color: var(--grey200);
  font-size: 24px; text-align: left; padding: 8px 8px 8px 8px; min-height: 52px;
}
.group-indicator { display: inline-flex; margin-right: 8px; color: var(--text); }
.group-indicator .icon { width: 30px; height: 30px; }
.group-title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card {
  display: flex; align-items: center; background: var(--grey800); margin: 4px 8px 8px; padding: 4px; min-height: 58px;
  box-shadow: 0 3px 4px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3); cursor: pointer;
  transition: background 0.1s, opacity 0.18s, transform 0.18s;
}
.card:active { background: var(--grey700); }
.card-enter { opacity: 0; transform: translateY(-12px); }
.card-leave { opacity: 0; transform: translateX(40px); }
.card-badge {
  flex: 0 0 auto; width: 42px; height: 42px; margin: 4px 0 4px 4px; display: flex; align-items: center; justify-content: center;
  color: var(--text); font-size: 24px; background: var(--highlight); overflow: hidden;
}
.card-badge.badge-small { font-size: 18px; }
.card-badge.badge-lg { width: 48px; height: 48px; margin: 4px; }
.card-badge.badge-lg.badge-small { font-size: 16px; }
.card-text { flex: 1 1 auto; min-width: 0; margin-left: 8px; align-self: stretch; display: flex; flex-direction: column; justify-content: center; }
.card-text-single { font-size: 22px; margin-left: 16px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { font-size: 16px; color: var(--text); overflow-wrap: anywhere; }
.card-sub { font-size: 14px; color: var(--text-secondary); overflow-wrap: anywhere; margin-top: 2px; }
.card-menu { flex: 0 0 48px; height: 48px; border: 0; background: transparent; color: var(--grey300); display: inline-flex; align-items: center; justify-content: center; }
.card-menu .icon { width: 30px; height: 30px; }
.card-menu:active { background: rgba(255, 255, 255, 0.12); border-radius: 50%; }
.seg-bold { font-weight: 700; color: var(--text); }
.seg-dim { color: var(--text-dim); }

.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 16px 96px; color: var(--grey700); text-align: center; pointer-events: none;
}
.empty-icon .icon { width: 128px; height: 128px; }
.empty-text { font-size: 18px; max-width: 480px; line-height: 1.35; }

.fab {
  position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--highlight); color: var(--text); display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3); z-index: 2;
}
.fab .icon { width: 36px; height: 36px; }
.fab:active { background: var(--highlight-dark); }

/* Drawer ------------------------------------------------------------------ */

.drawer-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 20; }
.drawer-scrim.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 280px; max-width: 85vw; background: var(--drawer-bg);
  transform: translateX(-100%); transition: transform 0.22s cubic-bezier(0.2, 0, 0, 1), visibility 0s 0.22s; z-index: 21;
  visibility: hidden; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top);
}
.drawer.is-open { transform: translateX(0); visibility: visible; transition: transform 0.22s cubic-bezier(0.2, 0, 0, 1); box-shadow: 4px 0 12px rgba(0, 0, 0, 0.5); }
.drawer-header { background: var(--highlight-shadow); padding: 16px; display: flex; align-items: center; gap: 16px; }
.drawer-icon { width: 56px; height: 56px; }
.drawer-title { font-size: 26px; color: var(--text); }
.drawer-sep { height: 1px; background: var(--grey900); }
.drawer-list { display: flex; flex-direction: column; padding: 8px 0; }
.drawer-item {
  display: flex; align-items: center; gap: 16px; height: 49px; padding: 0 16px; border: 0; background: transparent;
  color: var(--grey200); font-size: 14px; text-align: left;
}
.drawer-item .icon { opacity: 0.63; }
.drawer-item:active { background: var(--grey700); }

/* Dialogs ----------------------------------------------------------------- */

#overlays { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
#overlays > * { pointer-events: auto; }
.dialog-scrim {
  position: fixed; inset: 0; display: flex; align-items: stretch; justify-content: center; background: transparent;
  opacity: 0; transition: opacity 0.18s;
}
.dialog-scrim.is-open { opacity: 1; }
.dialog {
  display: flex; flex-direction: column; width: 100%; background: var(--bg-dialog); padding-top: env(safe-area-inset-top);
  transform: translateY(12px); transition: transform 0.18s;
}
.dialog-scrim.is-open .dialog { transform: none; }
.dialog-toolbar { padding-left: 0; }
.dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; position: relative; padding-bottom: env(safe-area-inset-bottom); }
.dialog-select-dice .dialog-body { overflow: hidden; }
.dialog-select-dice .pages { height: 100%; }
.dialog-select-dice .dialog-toolbar .toolbar-title { flex: 0 1 auto; }
.dialog-select-dice .dialog-toolbar .tabs { margin-left: auto; }
.dialog-heading { font-size: var(--size-input); font-weight: 400; margin: 16px 16px 8px; }
.dialog-form .dialog-body { padding: 16px; }
.field-label { display: block; font-size: 14px; color: var(--text-secondary); margin: 8px 0 4px; }
.field {
  width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--grey); color: var(--text); font-size: 22px; font-family: inherit;
  padding: 8px 4px; outline: none; border-radius: 0;
}
.field:focus { border-bottom: 2px solid var(--highlight); padding-bottom: 7px; }
.field-error { color: #FF6E6E; font-size: 13px; min-height: 18px; margin: 2px 0 6px; }
.dice-field {
  width: 100%; height: 44px; border: 0; border-bottom: 1.2px solid var(--grey); background: transparent; color: var(--text);
  font-size: 22px; text-align: left; padding: 0 5px; margin: 0 0 4px;
}
.dice-field:active { background: var(--grey900); }
.check-row { display: flex; align-items: center; gap: 12px; height: 48px; margin: 0 16px; font-size: 18px; cursor: pointer; }
.check-row input { width: 22px; height: 22px; accent-color: var(--highlight); margin: 0; }
.settings-row { margin: 16px; }
.settings-note { margin: 0 16px; color: var(--text-secondary); font-size: 14px; }
.dialog-sounds .list { padding: 0 8px 96px; }
.dialog-sounds .fab { position: fixed; }
.two-col { display: flex; gap: 16px; margin: 0 16px; }
.two-col > div { flex: 1 1 0; min-width: 0; }
.select {
  width: 100%; background: transparent; color: var(--text); border: 0; border-bottom: 1px solid var(--grey); font-size: 18px; font-family: inherit;
  padding: 8px 4px; border-radius: 0;
}
.select option { background: var(--bg-dialog); color: var(--text); }
.radio-list { margin: 0 16px; border-top: 1px solid var(--grey900); }
.radio-item {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 48px; border: 0; background: transparent; color: var(--text);
  font-size: 18px; text-align: left; padding: 0 12px;
}
.radio-item:active { background: var(--grey900); }
.radio-icon { display: inline-flex; color: var(--grey); }
.radio-item.is-selected .radio-icon { color: var(--highlight); }
.radio-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wide-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px; margin: 16px 16px calc(16px + env(safe-area-inset-bottom)); height: 48px; border: 0;
  background: var(--primary); color: var(--text); font-size: 15px; font-weight: 500; letter-spacing: 0.3px; flex: 0 0 auto;
}
.wide-btn:active { background: var(--grey700); }
.dialog-sound-editor .field-label { margin-top: 0; }
.dialog-sound-editor .field-error { margin: 0 16px; }

.about-header { background: var(--highlight-shadow); display: flex; flex-direction: column; align-items: center; padding: 32px 16px 40px; }
.about-icon { width: 96px; height: 96px; }
.about-title { font-size: 48px; margin-top: 8px; }
.about-body { padding: 24px 16px; text-align: center; color: var(--grey200); }
.about-version { font-size: 22px; margin-bottom: 16px; }
.about-text { font-size: 15px; line-height: 1.45; margin: 0 auto 12px; max-width: 480px; }
.about-strong { font-size: 16px; }
.about-small { font-size: 13px; color: var(--text-secondary); }
.about-link { color: var(--highlight); font-size: 18px; text-decoration: none; }

/* Alert dialog, popup menu, toast ----------------------------------------- */

.alert-scrim, .menu-scrim, .result-scrim { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.alert-scrim { background: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.15s; }
.alert-scrim.is-open { opacity: 1; }
.alert { background: var(--grey800); width: min(92vw, 400px); box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6); border-radius: 2px; }
.alert-message { padding: 24px; min-height: 96px; font-size: 18px; color: var(--grey300); line-height: 1.4; }
.alert-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 8px; }
.alert-btn { border: 0; background: transparent; min-width: 80px; height: 40px; padding: 0 8px; font-size: 18px; font-weight: 700; text-transform: none; }
.alert-positive { color: var(--highlight); }
.alert-negative { color: rgba(33, 150, 243, 0.53); }
.alert-btn:active { background: rgba(255, 255, 255, 0.1); }

.menu-scrim { background: transparent; }
.popup-menu {
  position: fixed; min-width: 168px; background: var(--grey800); padding: 8px 0; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6); border-radius: 2px;
  display: flex; flex-direction: column; transform-origin: top right; animation: menu-in 0.12s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
.popup-item { display: block; width: 100%; height: 48px; border: 0; background: transparent; color: var(--text); font-size: 16px; text-align: left; padding: 0 16px; white-space: nowrap; }
.popup-item:active { background: var(--grey700); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #323232; color: var(--text);
  padding: 14px 24px; border-radius: 4px; font-size: 14px; opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: 90vw;
}
.toast.is-open { opacity: 1; transform: translate(-50%, 0); }

/* Result popup ------------------------------------------------------------ */

.result-scrim { background: rgba(0, 0, 0, 0.4); opacity: 0; transition: opacity 0.15s; padding: 24px; }
.result-scrim.is-open { opacity: 1; }
.result-card {
  min-width: 200px; max-width: 100%; max-height: 100%; color: var(--text); text-align: center; display: flex; flex-direction: column;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6); transform: scale(0.92); transition: transform 0.15s;
}
.result-scrim.is-open .result-card { transform: none; }
.result-title { flex: 0 0 auto; font-size: 18px; padding: 16px 24px 0; }
.result-total { --total-size: var(--size-total); flex: 0 0 auto; font-size: var(--size-total); height: 176px; display: flex; align-items: center; justify-content: center; padding: 0 24px; white-space: nowrap; overflow: hidden; line-height: 1; }
.result-details { flex: 0 1 auto; min-height: 0; overflow-y: auto; font-size: 18px; padding: 0 24px 16px; overflow-wrap: anywhere; line-height: 1.35; }

/* Responsive -------------------------------------------------------------- */

@media (orientation: landscape) and (max-height: 560px) {
  :root { --toolbar-h: 48px; --size-total: 96px; }
  .icon-btn, .tab { height: 48px; }
  .icon-btn { width: 48px; }
  .krow-input { min-height: 52px; margin: 2px 0; flex: 0 0 auto !important; }
  .krow-hint { flex: 0 0 auto !important; }
  .krow-hint { min-height: 24px; }
  .khint { -webkit-line-clamp: 1; min-height: 24px; margin-bottom: 2px; }
  .result-total { height: 120px; }
  .about-header { padding: 16px; }
  .about-icon { width: 64px; height: 64px; }
  .about-title { font-size: 32px; }
}

@media (max-height: 640px) and (orientation: portrait) {
  :root { --size-num: 30px; --size-die: 28px; --size-roll: 36px; --size-input: 32px; --size-total: 96px; }
  .result-total { height: 140px; }
}

@media (max-width: 360px) {
  :root { --size-die-small: 24px; }
  .row-narrow { margin-left: 32px; margin-right: 32px; }
}

/* Floating dialogs on wide screens (the tablet presentation). */
@media (min-width: 600px) and (min-height: 500px) {
  .dialog-scrim { background: rgba(0, 0, 0, 0.55); align-items: center; padding: 24px; }
  .dialog { width: min(560px, 100%); max-height: min(92vh, 860px); border-radius: 2px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6); overflow: hidden; padding-top: 0; }
  .dialog-select-dice { height: min(92vh, 860px); }
  .dialog-sounds .fab { position: absolute; }
  .result-card { min-width: 320px; }
  .drawer { padding-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
