:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --border: #e2ded7;
  --text: #2b2621;
  --text-muted: #8a8175;
  --accent: #b5633a;
  --accent-dark: #954f2d;
  --played: #6b8f71;
  --unplayed: #b5633a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 24px 20px 0;
  max-width: 960px;
  margin: 0 auto;
}

.app-header h1 {
  font-size: 1.4rem;
  margin: 0 0 16px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: none;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input {
  min-width: 220px;
  flex-grow: 1;
}

select, input, textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.btn-primary, .btn-secondary, .btn-edit, .btn-delete {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

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

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

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

.btn-delete {
  background: var(--surface);
  border-color: var(--border);
  color: #b3413a;
}

.btn-toggle {
  background: none;
  border: none;
  color: var(--accent-dark);
  font-size: 0.85rem;
  padding: 2px 0;
  text-align: left;
  cursor: pointer;
  align-self: flex-start;
}

.details.hidden {
  display: none;
}

.card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.card-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  color: #fff;
}
.badge-played { background: var(--played); }
.badge-unplayed { background: var(--unplayed); }

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

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text);
}

.memo {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.simple-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.list-row-main strong { font-size: 0.95rem; }
.list-row-main .note {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.list-row-actions { display: flex; gap: 8px; flex-shrink: 0; }

.empty {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 26, 22, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 22px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

#puzzle-form, #creator-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#puzzle-form label, #creator-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 12px;
}
.form-row label { flex: 1; }

.checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
}

.required { color: #b3413a; margin-left: 2px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 480px) {
  .form-row { flex-direction: column; }
  .toolbar { flex-direction: column; align-items: stretch; }
}
