:root {
  color-scheme: light;
  --bg: #ead8b7;
  --panel: #fff9ee;
  --panel-strong: #fff4db;
  --line: #dcc39b;
  --line-strong: #c59655;
  --text: #312314;
  --muted: #7e6848;
  --accent: #a34f15;
  --accent-strong: #8b3d0a;
  --accent-soft: #ffe2c2;
  --danger: #b42318;
  --danger-soft: #fde8e4;
  --ok: #166534;
  --shadow: 0 20px 40px rgba(96, 66, 27, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.55), transparent 30%),
    linear-gradient(180deg, #f5ebd4 0%, var(--bg) 100%);
}

button,
select,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 12px 112px;
}

.app-header {
  margin: 0 0 14px;
  padding: 18px 18px 16px;
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.55), transparent 35%),
    linear-gradient(135deg, #fbf2dd 0%, #e8c990 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.app-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.app-title {
  margin: 12px 0 0;
  font-size: 29px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.app-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.summary-card {
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 249, 238, 0.82);
  border: 1px solid rgba(220, 195, 155, 0.95);
}

.summary-label {
  font-size: 12px;
  color: var(--muted);
}

.summary-value {
  margin-top: 5px;
  font-size: 20px;
  font-weight: 800;
}

.btn-main,
.btn-soft,
.btn-danger,
.btn-ghost {
  padding: 10px 14px;
  font-weight: 700;
}

.btn-main {
  background: linear-gradient(180deg, #b96327 0%, var(--accent) 100%);
  color: #fff;
}

.btn-soft {
  background: var(--panel);
  color: var(--accent-strong);
  border: 1px solid var(--line);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.18);
}

.app-main {
  display: grid;
  gap: 14px;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.panel-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent-strong);
  background: #f8e8c7;
  border: 1px solid rgba(197, 150, 85, 0.4);
}

.panel-note {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.toolbar-row,
.inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.toolbar-row {
  margin-bottom: 12px;
}

.tile-group-title {
  margin: 14px 0 8px;
  font-size: 15px;
  font-weight: 800;
  color: var(--accent-strong);
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.tile-card {
  background: linear-gradient(180deg, #fffdf7 0%, #f8ecd4 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 7px;
  text-align: center;
}

.tile-card.tile-card-win {
  border-color: var(--line-strong);
  box-shadow: inset 0 0 0 2px rgba(197, 150, 85, 0.18);
}

.tile-card-main {
  cursor: pointer;
}

.tile-card-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.tile-card-count {
  margin-top: 6px;
  font-size: 28px;
  line-height: 1;
  font-weight: 800;
  color: var(--accent-strong);
}

.tile-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.tile-action-btn {
  flex: 1;
  padding: 8px 0;
  background: #fff9ea;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.tile-action-btn.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--line-strong);
}

.tile-action-btn:disabled,
.red-card.disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tile-image {
  width: 68px;
  height: 96px;
  display: block;
  margin: 0 auto;
}

.tile-image.mini {
  width: 52px;
  height: 74px;
  margin: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 16px;
  background: #f8efe0;
  border: 1px solid var(--line);
}

.chip-text {
  font-size: 14px;
  color: var(--text);
  font-weight: 700;
}

.select-stack {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.select-field {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fffdf7;
}

.select-field label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
}

.select-field select {
  background: transparent;
  border: 0;
  color: var(--text);
  min-width: 0;
  width: 100%;
}

.meld-list,
.indicator-list,
.history-list,
.yaku-list,
.fu-list {
  display: grid;
  gap: 10px;
}

.list-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 12px;
  background: #fffcf4;
  border-radius: 16px;
  border: 1px solid rgba(220, 195, 155, 0.8);
}

.quick-grid,
.red-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.quick-card,
.red-card {
  padding: 10px 6px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fffdf7;
  text-align: center;
  cursor: pointer;
}

.quick-card,
.red-card,
.history-item,
.tile-action-btn,
.btn-main,
.btn-soft,
.btn-danger,
.btn-ghost {
  -webkit-tap-highlight-color: transparent;
}

.quick-card.active {
  border-color: var(--line-strong);
  background: #fff2d9;
}

.red-card {
  background: #fff5f2;
}

.red-card.active {
  border-color: #d35d2a;
  background: #ffe5d4;
}

.quick-text,
.red-text {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.switch-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fffdf7;
  font-weight: 700;
}

.switch-card input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.result-head {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 12px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fffdf7 0%, #f8edd8 100%);
  border: 1px solid var(--line);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
}

.stat-value {
  margin-top: 6px;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.35;
}

.result-message,
.warning-box,
.error-box,
.empty-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.55;
}

.result-message,
.empty-box {
  background: #fffdf7;
  border: 1px solid var(--line);
  color: var(--muted);
}

.warning-box {
  background: #fff7e5;
  color: #92400e;
  border: 1px solid rgba(217, 119, 6, 0.2);
}

.error-box {
  background: #fff0ef;
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.18);
}

.result-columns {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.subpanel {
  border-radius: 18px;
  padding: 14px;
  background: #fffdf7;
  border: 1px solid var(--line);
}

.subpanel h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.history-panel {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(43, 31, 18, 0.36);
  padding: 18px 14px;
  z-index: 60;
}

.history-panel.open {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.history-sheet {
  width: min(720px, 100%);
  max-height: 82vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 28px 28px 18px 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.history-meta {
  font-size: 13px;
  color: var(--muted);
}

.history-item {
  width: 100%;
  text-align: left;
  background: #fffdf7;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
}

.history-item-title {
  font-weight: 800;
}

.history-item-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.history-item-yaku {
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent-strong);
}

.floating-bar {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(456px, calc(100vw - 20px));
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 10px;
  border-radius: 24px;
  background: rgba(255, 249, 238, 0.92);
  border: 1px solid rgba(220, 195, 155, 0.95);
  box-shadow: 0 16px 32px rgba(96, 66, 27, 0.18);
  backdrop-filter: blur(14px);
  z-index: 40;
}

.floating-bar .btn-main,
.floating-bar .btn-soft,
.floating-bar .btn-ghost {
  min-height: 46px;
}

.usage-card {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.7);
  border: 1px dashed rgba(197, 150, 85, 0.55);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.install-banner {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff7e9;
  border: 1px solid var(--line);
}

.install-banner.visible {
  display: block;
}

@media (max-width: 720px) {
  .tile-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-strip {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .app-title {
    font-size: 25px;
  }

  .tile-grid,
  .quick-grid,
  .red-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .switch-grid,
  .result-head {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .floating-bar {
    grid-template-columns: 1fr 1fr;
  }

  .floating-bar .btn-main {
    grid-column: 1 / -1;
  }
}
