:root {
  --color-bg-start: #1a1a2e;
  --color-bg-mid: #16213e;
  --color-bg-end: #0f3460;
  --color-text: #ffffff;
  --color-text-muted: rgba(255, 255, 255, 0.5);
  --color-border: rgba(255, 255, 255, 0.2);
  --color-border-active: rgba(255, 255, 255, 0.8);
  --font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(145deg, var(--color-bg-start) 0%, var(--color-bg-mid) 50%, var(--color-bg-end) 100%);
  color: var(--color-text);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ========================================
   Canvas
   ======================================== */
#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ========================================
   Start Overlay (TAP TO START)
   ======================================== */
.start-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 500;
  cursor: pointer;
  background: transparent;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.start-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-text {
  font-size: 1.5rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.15em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  animation: start-pulse 2s ease-in-out infinite;
}

@keyframes start-pulse {
  0%, 100% {
    opacity: 0.7;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
}

/* ========================================
   UI Overlay
   ======================================== */
.ui-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 10;
}

/* ========================================
   Header Buttons
   ======================================== */
.header-buttons {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 100;
  pointer-events: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--color-text);
  cursor: pointer;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  border: 1px solid var(--color-border);
  backdrop-filter: blur(8px);
  transition: 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.05);
}

.btn:active {
  transform: scale(0.95);
}

/* ========================================
   Material Current Button
   ======================================== */
.material-current {
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--color-border);
  border-radius: 30px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  z-index: 100;
  transition: 0.15s ease;
  pointer-events: auto;
}

.material-current:hover {
  background: rgba(255, 255, 255, 0.2);
}

.material-current-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.material-current-icon::after {
  content: '';
  display: block;
  width: 8px;
  height: 5px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  margin: 8px 0 0 9px;
  transform: rotate(-30deg);
}

.material-current-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: #ffffff;
}

.material-current-arrow {
  margin-left: 4px;
  opacity: 0.7;
  color: #ffffff;
}

/* ========================================
   Hint
   ======================================== */
.hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  pointer-events: none;
  animation: hint-pulse 2s ease-in-out infinite;
  z-index: 100;
  display: none;
}

.hint.is-hidden {
  opacity: 0;
  transition: opacity 0.5s ease;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}

/* ========================================
   Modal
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: 0.2s ease;
  pointer-events: auto;
}

.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-radius: 24px 24px 0 0;
  padding: 20px;
  z-index: 201;
  transform: translateY(100%);
  transition: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow-y: auto;
}

.modal-overlay.is-open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #ffffff;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   Material Grid
   ======================================== */
.material-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.material-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: 0.2s ease;
}

.material-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.material-item.is-selected {
  border-color: var(--color-border-active);
  background: rgba(255, 255, 255, 0.15);
}

.material-item-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  position: relative;
}

.material-item-icon::after {
  content: '';
  position: absolute;
  top: 10px;
  left: 12px;
  width: 12px;
  height: 7px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  transform: rotate(-30deg);
}

.material-item-name {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.material-item.is-selected .material-item-name {
  color: var(--color-text);
}

/* ========================================
   Ripple Effect
   ======================================== */
.ripple {
  position: fixed;
  width: 80px;
  height: 80px;
  margin-left: -40px;
  margin-top: -40px;
  border-radius: 50%;
  pointer-events: none;
  animation: ripple-expand 0.5s ease-out forwards;
  z-index: 5;
}

@keyframes ripple-expand {
  0% {
    transform: scale(0);
    opacity: 0.5;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}
