:root {
  --bordeaux: #722F37;
  --bordeaux-dark: #4A1C23;
  --bordeaux-deeper: #2D1015;
  --gold: #C9A96E;
  --gold-light: #E8D5A8;
  --cream: #FAF6F0;
  --text: #2C1810;
  --text-light: #8C7B6B;
  --white: #FFFFFF;
  --shadow: 0 2px 12px rgba(45, 16, 21, 0.12);
  --shadow-lg: 0 8px 32px rgba(45, 16, 21, 0.18);
  --radius: 12px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── Login Screen ── */
#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bordeaux-deeper), var(--bordeaux-dark), var(--bordeaux));
  padding: 1.5rem;
}

#login-screen.hidden { display: none; }

.login-container {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.login-container h1 {
  font-family: 'Playfair Display', serif;
  color: var(--bordeaux);
  font-size: 1.6rem;
  margin-bottom: 0.25rem;
}

.login-container > p {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.login-container input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid #E0DBD5;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  margin-bottom: 1rem;
  background: var(--cream);
  transition: border-color 0.2s;
}

.login-container input:focus {
  outline: none;
  border-color: var(--bordeaux);
}

.login-error {
  color: var(--bordeaux);
  font-size: 0.8rem;
  margin-top: 0.75rem;
}

.login-error.hidden { display: none; }

/* Header */
header {
  background: linear-gradient(135deg, var(--bordeaux-dark), var(--bordeaux));
  color: var(--white);
  padding: 2rem 1.5rem 1rem;
  text-align: center;
  position: relative;
}

header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

header .subtitle {
  font-size: 0.75rem;
  color: var(--gold-light);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 0.25rem;
}

.icon-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--gold-light);
  font-size: 1.4rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.icon-btn:hover { opacity: 1; }

/* Tab Bar */
.tab-bar {
  display: flex;
  background: var(--bordeaux-dark);
  padding: 0;
}

.tab {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  font-family: inherit;
}

.tab.active {
  color: var(--white);
  border-bottom-color: var(--gold);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  font-family: 'Playfair Display', serif;
  color: var(--bordeaux);
  margin-bottom: 0.5rem;
}

.modal-content p {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1rem;
}

.modal-content input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid #DDD;
  border-radius: 8px;
  font-size: 0.95rem;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--bordeaux);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
}

.modal-actions button {
  flex: 1;
  padding: 0.7rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.modal-actions button:active { transform: scale(0.97); }

.modal-actions button:first-child {
  background: var(--bordeaux);
  color: var(--white);
}

.modal-actions .secondary {
  background: #EEE;
  color: var(--text);
}

/* Main */
main {
  max-width: 600px;
  margin: 0 auto;
  padding: 1.25rem;
}

main.hidden { display: none; }

#app-container.hidden { display: none; }

/* Capture */
.capture-section {
  margin-bottom: 1.5rem;
}

.capture-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, var(--bordeaux), var(--bordeaux-dark));
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.capture-btn:active {
  transform: scale(0.98);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.camera-icon { font-size: 1.3rem; }

#preview-container {
  position: relative;
  margin-top: 1rem;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#preview-container.hidden { display: none; }

#preview-img {
  width: 100%;
  display: block;
  max-height: 260px;
  object-fit: cover;
}

#analyzing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(45, 16, 21, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--white);
  font-size: 0.95rem;
}

#analyzing-overlay.hidden { display: none; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Form */
#wine-form {
  background: var(--white);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 0.35rem;
  letter-spacing: 0.03em;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid #E0DBD5;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--cream);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--bordeaux);
  box-shadow: 0 0 0 3px rgba(114, 47, 55, 0.1);
}

.form-group textarea { resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Star Rating */
.star-rating {
  display: flex;
  gap: 0.25rem;
}

.star-rating .star {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: #DDD;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s, transform 0.1s;
}

.star-rating .star.active {
  color: var(--gold);
}

.star-rating .star:hover {
  transform: scale(1.15);
}

.star-display {
  font-size: 1rem;
  color: #DDD;
}

.star-display.filled {
  color: var(--gold);
}

.save-btn {
  width: 100%;
  padding: 0.85rem;
  background: var(--bordeaux);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 0.5rem;
  font-family: inherit;
}

.save-btn:hover { background: var(--bordeaux-dark); }
.save-btn:active { transform: scale(0.98); }
.save-btn.hidden { display: none; }

/* Wine List */
#wine-list h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--bordeaux);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1.5px solid var(--gold-light);
}

#empty-message {
  text-align: center;
  color: var(--text-light);
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 2rem 0;
}

.wine-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  border-left: 4px solid var(--bordeaux);
  position: relative;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.wine-card .card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.wine-card .card-actions button,
.wine-card .card-actions a {
  background: var(--cream);
  border: 1.5px solid #E0DBD5;
  border-radius: 6px;
  color: var(--text-light);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  transition: background 0.2s, color 0.2s;
  text-decoration: none;
  display: inline-block;
}

.wine-card .card-actions .edit-btn:hover {
  background: var(--gold-light);
  color: var(--bordeaux-dark);
}

.wine-card .card-actions .delete-btn:hover {
  background: #F5D5D8;
  color: var(--bordeaux);
}

.wine-card .card-actions .map-link:hover {
  background: #D5E8D4;
  color: #2D6A2E;
}

.wine-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.3rem;
}

.wine-card .wine-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--bordeaux-dark);
}

.wine-card .wine-year {
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 700;
  background: var(--bordeaux-deeper);
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.wine-card .card-rating {
  margin-bottom: 0.4rem;
}

.wine-card .wine-meta {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 0.4rem;
}

.wine-card .wine-meta span + span::before {
  content: ' · ';
}

.wine-card .wine-comment {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.6;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #F0ECE6;
}

.wine-card .wine-pairing {
  margin-top: 0.6rem;
  padding: 0.7rem 0.85rem;
  background: linear-gradient(135deg, #FBF7F0, #F5EDE0);
  border-radius: 8px;
  border-left: 3px solid var(--gold);
}

.wine-card .wine-pairing .pairing-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.wine-card .wine-pairing p {
  font-size: 0.83rem;
  color: var(--text);
  line-height: 1.65;
  margin: 0;
}

.wine-card .card-image {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

/* Search Tab */
.search-section {
  text-align: center;
}

.search-section h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--bordeaux);
  margin-bottom: 0.5rem;
}

.search-section .form-group {
  text-align: left;
}

#dish-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 0;
  color: var(--text-light);
}

#dish-loading.hidden { display: none; }
#dish-result.hidden { display: none; }

.dish-result-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-top: 1.25rem;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text);
  border-left: 4px solid var(--gold);
}

/* Analysis Tab */
.analysis-section {
  text-align: center;
}

.analysis-section h2,
#recommend-section h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--bordeaux);
  margin-bottom: 0.5rem;
}

.analysis-desc {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1.25rem;
}

#analysis-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 0;
  color: var(--text-light);
}

#analysis-loading.hidden { display: none; }

.analysis-card,
.recommend-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-top: 1.25rem;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text);
  border-left: 4px solid var(--gold);
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.recommend-card {
  border-left-color: var(--bordeaux);
}

.wine-link {
  color: var(--bordeaux);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1.5px solid var(--gold-light);
  transition: border-color 0.2s;
}

.wine-link:hover {
  border-bottom-color: var(--bordeaux);
}

#recommend-section {
  margin-top: 2rem;
}

#recommend-section.hidden { display: none; }
#analysis-result.hidden { display: none; }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bordeaux-dark);
  color: var(--white);
  padding: 0.75rem 1rem 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 90vw;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 9.5s forwards;
}

.toast-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s;
}

.toast-close:hover { color: var(--white); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; pointer-events: none; }
}
