/* BridgeMaster Companion — senior-friendly, offline-first */

:root {
  --accent: #0D5C46;
  --accent-hover: #0F6E54;
  --accent-soft: #D8F3E8;
  --accent-ink: #0A3D2F;
  --bg: #F4F1EB;
  --surface: #FFFFFF;
  --surface-2: #EDE9E1;
  --felt: #0F4A38;
  --felt-edge: #0A3428;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D3D1;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --red-suit: #B91C1C;
  --black-suit: #1C1917;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08), 0 4px 16px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 8px 30px rgba(28, 25, 23, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --space: 1rem;
  --touch: 48px;
  --max: 960px;
}

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

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

img {
  max-width: 100%;
}

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

button {
  cursor: pointer;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.6rem;
  flex-shrink: 0;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.main-nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.65rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.nav-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.nav-btn.is-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* Main */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  flex: 1;
  width: 100%;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  color: var(--accent-ink);
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
  max-width: 42rem;
}

.row-between {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 650;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #991B1B;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent-ink);
  min-height: var(--touch);
  padding: 0.5rem 0.75rem;
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-sm {
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  font-size: 0.95rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 0.75rem 0;
}

.icon-btn {
  width: var(--touch);
  height: var(--touch);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 1.5rem;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--text);
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* Panels & forms */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.15rem;
}

.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  color: var(--accent-ink);
}

.muted {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-grow {
  grid-column: 1 / -1;
}

@media (min-width: 640px) {
  .field-grow {
    grid-column: auto;
  }
  .filter-grid .field-grow {
    grid-column: span 2;
  }
}

.field label,
fieldset legend {
  font-weight: 600;
  color: var(--accent-ink);
  font-size: 0.95rem;
}

.field input,
.field select,
.field textarea,
.modal-body input,
.modal-body select,
.modal-body textarea {
  min-height: var(--touch);
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  width: 100%;
}

.field textarea,
.modal-body textarea,
#export-text,
#result-notes {
  min-height: 5rem;
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.check-label {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-height: var(--touch);
  padding: 0.5rem 0;
  cursor: pointer;
}

.check-label input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.2rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.result-summary {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-list.compact .item-card {
  padding: 0.85rem 1rem;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}

.item-card h3,
.item-card .card-title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.item-card .meta {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
}

.item-card .body {
  margin: 0 0 0.65rem;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--text);
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-sample {
  background: #E0E7FF;
  color: #3730A3;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1.25rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 1rem;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.stat-card .stat-label {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Play table */
.play-table {
  margin-top: 0.25rem;
}

.play-status {
  background: var(--accent-soft);
  border: 1px solid #A7D9C4;
  color: var(--accent-ink);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-weight: 650;
  margin-bottom: 1rem;
}

.table-layout {
  background: linear-gradient(160deg, var(--felt) 0%, var(--felt-edge) 100%);
  border-radius: 18px;
  padding: 1rem 0.75rem 1.25rem;
  color: #F0FDF4;
  box-shadow: var(--shadow-lg);
  margin-bottom: 1rem;
}

.seat-label {
  font-size: 0.9rem;
  font-weight: 650;
  opacity: 0.95;
  margin-bottom: 0.4rem;
  text-align: center;
}

.seat-role {
  font-weight: 500;
  opacity: 0.85;
}

.seat-north,
.seat-south {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.seat-middle {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) minmax(140px, 1.4fr) minmax(70px, 1fr);
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0;
}

.seat-west,
.seat-east {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hand-row,
.hand-col {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
  min-height: 3.2rem;
}

.hand-col {
  flex-direction: column;
  align-items: center;
}

.playing-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 3.2rem;
  padding: 0.25rem 0.35rem;
  border-radius: 8px;
  border: 2px solid #E7E5E4;
  background: #FFFEFB;
  color: var(--black-suit);
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  line-height: 1.1;
}

.playing-card.red {
  color: var(--red-suit);
}

.playing-card.face-down {
  background: linear-gradient(145deg, #1E3A8A, #1E40AF);
  color: #DBEAFE;
  border-color: #1E3A8A;
  font-size: 0.85rem;
}

.playing-card.is-playable {
  cursor: pointer;
  border-color: #FBBF24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.5), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.playing-card.is-playable:hover,
.playing-card.is-playable:focus-visible {
  transform: translateY(-4px);
  background: #FFFBEB;
}

.playing-card.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.playing-card.card-btn {
  min-width: 2.75rem;
  min-height: 3.4rem;
}

.trick-area {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  padding: 0.65rem;
  min-height: 7.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.trick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  min-height: 3.5rem;
}

.trick-slot {
  min-width: 3rem;
  min-height: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.75rem;
  opacity: 0.95;
}

.trick-meta {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0.9;
}

.auction-log {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.auction-cell {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.45rem;
  text-align: center;
  font-weight: 650;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auction-cell.head {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.85rem;
}

.bid-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.result-panel .result-text {
  font-size: 1.1rem;
  margin: 0 0 0.85rem;
}

/* Lessons / conventions content */
.lesson-body h4,
.conv-body h4 {
  margin: 1rem 0 0.4rem;
  color: var(--accent-ink);
}

.lesson-body ul,
.conv-body ul {
  margin: 0.35rem 0 0.75rem;
  padding-left: 1.25rem;
}

.lesson-body li,
.conv-body li {
  margin-bottom: 0.35rem;
}

.progress-bar {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0 0.25rem;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* Bidding practice */
.hand-diagram {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.75rem 0;
  padding: 0.85rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.scenario-meta {
  font-weight: 650;
  color: var(--accent-ink);
}

.scenario-auction {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-weight: 600;
}

.bid-choices {
  border: none;
  padding: 0;
  margin: 1rem 0 0;
}

.bid-choices .choice-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.choice-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--touch);
  padding: 0.55rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.choice-label:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice-label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.choice-label input {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
}

.feedback {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
}

.feedback.is-correct {
  background: var(--success-soft);
  border-color: #86EFAC;
  color: var(--success);
}

.feedback.is-wrong {
  background: var(--warn-soft);
  border-color: #FCD34D;
  color: var(--warn);
}

.feedback p {
  margin: 0.35rem 0 0;
}

.feedback strong {
  display: block;
  font-size: 1.05rem;
}

/* Reminders */
.reminder-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.reminder-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.reminder-item.is-due {
  background: var(--warn-soft);
  border-color: #FCD34D;
}

.reminder-item.is-done {
  opacity: 0.7;
}

.reminder-text {
  flex: 1;
  min-width: 12rem;
  margin: 0;
  font-weight: 600;
}

.reminder-due {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Insights */
.insight-section {
  margin-bottom: 1.15rem;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 7rem 1fr 3rem;
  gap: 0.5rem;
  align-items: center;
}

.bar-track {
  height: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.bar-count {
  text-align: right;
  font-weight: 650;
  color: var(--text-muted);
}

/* Modal */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
}

.modal-card {
  position: relative;
  width: min(100%, 560px);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent-ink);
}

.modal-body {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
  padding: 0.85rem 1.15rem 1.15rem;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 300;
  max-width: min(92vw, 420px);
  background: var(--accent-ink);
  color: #fff;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

/* Export */
.export-box {
  margin-top: 0.75rem;
}

.export-box label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--accent-ink);
}

.export-box textarea {
  width: 100%;
  min-height: 8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
}

.danger-panel {
  border-color: #FECACA;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  font-size: 0.95rem;
}

/* Detail blocks inside cards */
.detail-block {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.kv {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0.5rem 0;
}

.kv dt {
  font-weight: 650;
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
}

@media (max-width: 520px) {
  .brand h1 {
    font-size: 1.2rem;
  }

  .seat-middle {
    grid-template-columns: 1fr 1.2fr 1fr;
  }

  .playing-card {
    min-width: 2.2rem;
    min-height: 2.9rem;
    font-size: 0.9rem;
  }

  .bar-row {
    grid-template-columns: 5.5rem 1fr 2.5rem;
  }

  .kv {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .playing-card.is-playable:hover,
  .playing-card.is-playable:focus-visible {
    transform: none;
  }

  .btn,
  .nav-btn {
    transition: none;
  }
}
